Use graphicex to convert BMP to PNG. After transfer, it is still in BMP format. I do not know how to write it? Please help

Source: Internet
Author: User
Use graphicex to convert BMP to PNG. After transfer, it is still in BMP format. I do not know how to write it? 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;

Use 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;

See my reply in the following post:

Http://community.csdn.net/Expert/topic/5172/5172039.xml? Temp =. 6034052.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.