用GraphicEx将Bmp转PNG,转出后还是BMP格式.不知如何写?请帮忙 Delphi / Windows SDK/APIhttp://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