Author: lyboy99
E-mail: lyboy99@sina.com
URL: http://hnh.126.com
We provide several common image format conversion methods and their conversion functions.
Hope to help you
1. Convert ICO icon to BMP format
2. 32x32 BMP Format Image conversion to ICO format
3. Convert BMP-> JPEG file format
4. Convert jpeg to BMP Function
5. Functions for converting BMP to JPEG file format
Bytes -------------------------------------------------------------------------------------------------------------------------
1. Chinese: Convert ICO icons to BMP format
English :( conversion from ICO to BMP)
--------------------------------------------------------
VaR
Icon: ticon;
Bitmap: tbitmap;
Begin
Icon: = ticon. Create;
Bitmap: = tbitmap. Create;
Icon. loadfromfile ('C:/picture. ICO ');
Bitmap. Width: = icon. width;
Bitmap. Height: = icon. height;
Bitmap. Canvas. Draw (0, 0, icon );
Bitmap. savetofile ('C:/picture.bmp ');
Icon. Free;
Bitmap. Free;
==========================================
2. Chinese: 32x32 BMP Format Image converted to ICO format
English: 32x32 bit bitmaps to ico's
-----------------------------------
Unit Main;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls,
Forms, dialogs, extctrls, stdctrls;
Type
Tform1 = Class (tform)
Button1: tbutton;
Image1: timage;
Image2: timage;
Procedure button1click (Sender: tobject );
Procedure formcreate (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (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 (application. exename)
+ 'Myfile.bmp ');
End;
Procedure tform1.formcreate (Sender: tobject );
Begin
Image1.picture. Icon. loadfromfile ('C:/myicon. ICO ');
End;
End.
========================================================== ======================================
3. Chinese: Convert BMP-> JPEG file format
Englsh: Convert the bitmap into a jpeg file format
------------------------------------------------------------------
VaR
Myjpeg: tsf-image;
Image1: timage;
Begin
Image1: = timage. Create;
Myjpeg: = tsf-image. Create;
Image1.loadfromfile ('testimage. BMP '); // read bitmap files
Myjpeg. Assign (image1.picture. Bitmap );
Object
Myjpeg. savetofile ('myphoto image. jpg '); // save JPEG
End;
--------------------------------------------------------------------
4. Convert jpeg to BMP Function
Procedure jpg2bmp (const source, DEST: string );
VaR
Myjpeg: tsf-image;
BMP: tbitmap;
Begin
BMP: = tbitmap. Create;
Myjpeg: = tsf-image. Create;
Try
Myjpeg. loadfromfile (source );
BMP. Assign (myjpeg );
BMP. savetofile (DEST );
Finally
BMP. Free;
Myjpeg. Free;
End;
End;
----------------------------------------------------------
5. Functions for converting BMP to JPEG file format
----------------------------------------------------------
Procedure BMP 2jpg (const source, DEST: string; const scale: byte );
VaR
Myjpeg: tsf-image;
Image1: timage;
Begin
Image1: = timage. Create (application );
Myjpeg: = tsf-image. Create;
Try
Image1.picture. bitmap. loadfromfile (source );
Myjpeg. Assign (image1.picture. Bitmap );
Myjpeg. compressionquality: = scale;
Myjpeg. Compress;
Myjpeg. savetofile (DEST );
Finally
Image1.free;
Myjpeg. Free;
End;
End;