用GraphicEx将Bmp转PNG,转出后还是BMP格式.不知如何写?请帮忙

用GraphicEx将Bmp转PNG,转出后还是BMP格式.不知如何写?请帮忙 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061008142348265.html
png   :=   TPNGGraphic.Create;  
              try  
                  Image1.Picture.LoadFromFile(sBmpName);  
                  if   Image1.Picture.Graphic   is   TBitmap   then  
                        png.Assign(Image1.Picture.Graphic)  
                  else  
                  begin  
                      png.PixelFormat   :=   pf16bit;  
                      png.Width   :=   Image1.Picture.Width;  
                      png.Height   :=   Image1.Picture.Height;  
                      png.Canvas.Draw(0,   0,   Image1.Picture.Graphic);  
                  end;  
                  png.SaveToFile(sSaveName);  
              finally  
                  png.Free;  
              end;

用GDI+  
  function   TmainForm.SaveFileToPng(SaveBmp:TBitMap32;FileName   :String):Boolean;  
  var  
    B:TBitmap32;  
    encoderClsid:   TGUID;  
    TempGBitmap   :TGPbitmap;  
    i,j   :integer;  
    color:   Cardinal;  
    stat:   TStatus;  
  begin  
      result   :=false;  
      B   :=TBitMap32.Create;  
      B.DrawMode   :=   dmBlend;  
      B.Assign(SaveBmp);  
      TempGBitMap   :=TGPbitMap.Create(B.width,   B.height,   PixelFormat32bppARGB);  
      for   i   :=0   to   B.Width   -1   do  
        for   j   :=0   to   B.Height   -1   do  
          begin  
                Color:=B.Pixel[i,j];  
                TempGBitMap.SetPixel(i,j,Color);  
            end;  
      GetEncoderClsid('image/png',   encoderClsid);  
      stat   :=   TempGBitMap.Save(FileName,   encoderClsid,   nil);  
      if   Stat=Ok   then  
          result   :=true;  
  end;

请参见下面帖中我的回复:  
   
  http://community.csdn.net/Expert/topic/5172/5172039.xml?temp=.6034052

转载于:https://www.cnblogs.com/delphi2007/archive/2009/03/13/1410287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
procedure BitmapFileToPNG(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin Bitmap := TBitmap.Create; PNG := TPNGObject.Create; {In case something goes wrong, free booth Bitmap and PNG} try Bitmap.LoadFromFile(Source); PNG.Assign(Bitmap); //Convert data into png PNG.SaveToFile(Dest); finally Bitmap.Free; PNG.Free; end end; Converting from PNG file to Windows bitmap file The above inverse. Loads a png and saves into a bitmap procedure PNGFileToBitmap(const Source, Dest: String); var Bitmap: TBitmap; PNG: TPNGObject; begin PNG := TPNGObject.Create; Bitmap := TBitmap.Create; {In case something goes wrong, free booth PNG and Bitmap} try PNG.LoadFromFile(Source); Bitmap.Assign(PNG); //Convert data into bitmap Bitmap.SaveToFile(Dest); finally PNG.Free; Bitmap.Free; end end; Converting from TImage to PNG file This method converts from TImage to PNG. It has full exception handling and allows converting from file formats other than TBitmap (since they allow assigning to a TBitmap) procedure TImageToPNG(Source: TImage; const Dest: String); var PNG: TPNGObject; BMP: TBitmap; begin PNG := TPNGObject.Create; {In case something goes wrong, free PNG} try //If the TImage contains a TBitmap, just assign from it if Source.Picture.Graphic is TBitmap then PNG.Assign(TBitmap(Source.Picture.Graphic)) //Convert bitmap data into png else begin //Otherwise try to assign first to a TBimap BMP := TBitmap.Create; try BMP.Assign(Source.Picture.Graphic); PNG.Assign(BMP); finally BMP.Free; end; end; //Save to PNG format PNG.SaveToFile(Dest); finally PNG.Free; end end;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值