unit FMX.Canvas.D2D;
initialization
TTextLayoutManager.RegisterTextLayout(TTextLayoutD2D, TCanvasD2D);
TBitmapCodecManager.RegisterBitmapCodecClass(SBMPImageExtension, SVBitmaps, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SJPGImageExtension, SVJPGImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SJPEGImageExtension, SVJPGImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SPNGImageExtension, SVPNGImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SGIFImageExtension, SVGIFImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(STIFImageExtension, SVTIFFImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(STIFFImageExtension, SVTIFFImages, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SICOImageExtension, SVIcons, True, TBitmapCodecWIC);
TBitmapCodecManager.RegisterBitmapCodecClass(SHDPImageExtension, SWMPImages, True, TBitmapCodecWIC);
end.
class procedure TBitmapCodecManager.RegisterBitmapCodecClass(const Extension, Description: string; const CanSave: Boolean;
const BitmapCodecClass: TCustomBitmapCodecClass);
var
LDescriptor: TBitmapCodecClassDescriptor;
begin
if FBitmapCodecClassDescriptors = nil then
FBitmapCodecClassDescriptors := TList<TBitmapCodecClassDescriptor>.Create;
LDescriptor.Extension := Extension;
LDescriptor.Description := Description;
LDescriptor.BitmapCodecClass := BitmapCodecClass;
LDescriptor.CanSave := CanSave;
FBitmapCodecClassDescriptors.Add(LDescriptor);
end;
class function TBitmapCodecManager.LoadFromFile(const AFileName: string; const Bitmap: TBitmapSurface;
const MaxSizeLimit: Cardinal = 0): Boolean;
var
CodecClass: TCustomBitmapCodecClass;
Codec: TCustomBitmapCodec;
begin
CodecClass := FindBitmapCodecDescriptor(ExtractFileExt(AFileName),
TBitmapCodecDescriptorField.Extension).BitmapCodecClass;
if CodecClass <> nil then
begin
Codec := CodecClass.Create;
try
Result := Codec.LoadFromFile(AFileName, Bitmap, MaxSizeLimit);
finally
Codec.Free;
end;
end
else
Result := False;
end;
procedure TBitmap.LoadFromFile(const AFileName: string);
var
Surf: TBitmapSurface;
begin
Surf := TBitmapSurface.Create;
try
if TBitmapCodecManager.LoadFromFile(AFileName, Surf, CanvasClass.GetAttribute(TCanvasAttribute.MaxBitmapSize)) then
Assign(Surf)
else
raise EBitmapLoadingFailed.CreateFMT(SBitmapLoadingFailedNamed, [AFileName]);
finally
Surf.Free;
end;
end;