zoukankan      html  css  js  c++  java
  • FMX解析BMP文件工厂

    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;

  • 相关阅读:
    快速掌握GIT
    Codeigniter+PHPExcel导出Excel文件
    git结构拓扑图
    (转)MVC新手指南
    (转)jQuery插件开发 其实很简单
    (转)Asp.net缓存简介
    (转)让ASP.NET MVC页面返回不同类型的内容
    (转)2010 .NET面试题整理之基础篇
    (转) .NET对象的XML序列化和反序列化
    (转)2010面试攻略
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/5168947.html
Copyright © 2011-2022 走看看