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;

最新文章

  1. 理解Docker(3):Docker 使用 Linux namespace 隔离容器的运行环境
  2. mybatis-config.xml简单笔记
  3. 关于 MAXScript 中文路径返回上级目录(精简版)
  4. Linux常用压缩和解压命令
  5. 【kAri OJ620】winoros的树
  6. linux设备驱动归纳总结(六):3.中断的上半部和下半部——tasklet【转】
  7. SqlServer存储过程
  8. Javascript与Ajax
  9. 线段树(单点更新)HDU1166、HDU1742
  10. redis常见错误
  11. PAT 1002 Hello World for U (20)
  12. android application简要类(一)
  13. layoutSubview触发时机
  14. JDK、JRE、JVM详解
  15. 为什么在Python里推荐使用多进程而不是多线程
  16. Android监听自身卸载,弹出用户反馈调查
  17. 深入学习MySQL事务:ACID特性的实现原理
  18. ElasticSearch 6.2 Mapping参数说明及text类型字段聚合查询配置
  19. 翻译:赋值操作符(:=)(已提交到MariaDB官方手册)
  20. springcloud-4:服务注册(hello-service)

热门文章

  1. CentOS7.5下时间戳转换为时间
  2. 安装Caffe时出现的错误
  3. controller中,Failed to Initialize. Reason: TimeOut虚拟用花初始化超时
  4. JavaScript之setInterval() 函数
  5. JS获取select的value和text值的简单实例
  6. Python添加系统路径BASE_DIR
  7. javascript入门教程笔记
  8. Ubuntu16.04安装mongodb 及使用
  9. python解决组合问题
  10. functools.wraps 带参数的装饰器 多个装饰器装饰同一个函数