[Delphi Technology] Delphi Common Image Format conversion technology

Source: Internet
Author: User

Tjpegscale = (jsfullsize, jshalf, Jsquarter, jseighth);//Picture size (all, 1/2,1/4,1/8)
tbitmap.pixelformat:=pf8bit;//number of pictures (8,24)

To provide you with a few commonly used image format conversion method and its conversion function
I hope I can help you.
1. ico icon to convert BMP format
2.32x32 BMP format image converted to ICO format
3. Convert bmp->jpeg file format
4.JPEG conversion to BMP function
5.BMP convert to JPEG file Format function
------------------------------------------------------------------------------------------
1.chinese:ico icon Conversion BMP format
中文版:(Conversion from ICO to BMP)
--------------------------------------------------------

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:tjpegimage;
Image1:timage;
Begin
Image1:= timage.create;
Myjpeg:= tjpegimage.create;
Image1.loadfromfile (' testimage.bmp '); Read Bitmap file
Myjpeg.assign (IMAGE1.PICTURE.BITMAP);
Object
Myjpeg.savetofile (' myjpegimage.jpg '); Save JPEG
End

--------------------------------------------------------------------
4.JPEG conversion to BMP function

procedure jpg2bmp (const source,dest:string);
var
  Myjpeg:tjpegimage;
  Bmp:tbitmap;
Begin
Bmp:=tbitmap. Create;
myjpeg:= tjpegimage.create;
Try
  myjpeg. LoadFromFile (source);
  BMP. Assign (Myjpeg);
  BMP. SaveToFile (dest);
finally
  Bmp.free;
  Myjpeg. Free;
End;
End;

----------------------------------------------------------
5.BMP convert to JPEG file Format function
----------------------------------------------------------
Procedure bmp2jpg (const source,dest:string;const scale:byte);
Var
Myjpeg:tjpegimage;
Image1:timage;
Begin
image1:= timage.create (application);
Myjpeg:= tjpegimage.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
-----------------------------------------------------------------------

[Delphi Technology] Delphi Common Image Format conversion technology

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.