Delphi converts an ICO to BMP

Source: Internet
Author: User

(1) method 1

VaR

Icon: ticon;

Bitmap: tbitmap;

Begin

Icon: = ticon. Create;

Bitmap: = tbitmap. Create;

Icon. loadfromfile ('C: \ picture. ICO '); // load an ico

From file

Bitmap. Width: = icon. width;

Bitmap. Height: = icon. height;

Bitmap. Canvas. Draw (0, 0, icon );

Bitmap. savetofile ('C: \ picture.bmp '); // convert ICO

BMP!

Icon. Free;

Bitmap. Free;

End;

(2) method 2

Procedure tform1.convertclick (Sender: tobject );

VaR

Windc, srcdc, destdc: HDC;

Oldbitmap: hbitmap;

Iinfo: ticoninfo;

Begin

Geticoninfo (image1.picture. Icon. Handle, iinfo );

Windc: = getdc (handle );

Srcdc: = createcompatibledc (windc );

Destdc: = createcompatibledc (windc );

Oldbitmap: = SelectObject (destdc, iinfo. hbmcolor );

Oldbitmap: = SelectObject (srcdc, iinfo. hbmmask );

Bitblt (destdc, 0, 0,

Image1.picture. Icon. Width, image1.picture. Icon. Height, srcdc,

0, 0, srcpaint );

Image2.picture. bitmap. Handle: = SelectObject (destdc,

Oldbitmap );

Deletedc (destdc );

Deletedc (srcdc );

Deletedc (windc );

Image2.picture. bitmap. savetofile (extractfilepath (applicat

Ion. exename) + 'myfile.bmp ');

End;

Procedure tform1.formcreate (Sender: tobject );

Begin

Image1.picture. Icon. loadfromfile ('C: \ myicon. ICO ');

End;

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.