Delphi common image format conversion technology

zhaozj2021-02-11  151

Common image format conversion technology Author: lyboy99 e-mail: lyboy99@sina.com url: http://hnh.126.com

Provide several common image format conversion methods and their conversion functions I hope to help you 1. ICO icon Conversion BMP format 2. 32x32 BMP format image converted to ICO Format 3. Convert BMP-> JPEG File Format 4 .Jpeg converted to BMP function 5.bmp converted to JPEG file format function ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------------------------------------ 1.CHINESE: ICO icon Conversion BMP Format English: (Conversion from ICO to BMP) ---------------------------------------------- ------------

Var icon: ticon; begin icon: = ticon.create; bitmap: = tbitmap.create; icon.LoadFromFile ('c: /pture.ico'); bitmap.width: = icon.width; bitmap.height : = Icon.height; bitmap.canvas.draw (0, 0, icon); Bitmap.Savetofile ('c: /Picture.bmp'); icon.free; bitmap.free; ========= ================================================================================================================================================================ # ------------------------------ 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 (deletedc, OldBitmap); deletedc (deletedc DELETEDC (SRCDC); deletedc (Windc);

Image2.picture.bitmap.savetofile (extractfilepath (application.exename) 'myfile.bmp');

Procedure tform1.formcreate (sender: TOBJECT); Begin Image1.Picture.icon.LoadFromFile ('c: /myicon.ico');

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

-------------------------------------------------- ------------------ 4.jpeg converted to BMP functions

procedure Jpg2Bmp (const source, dest: string); var MyJpeg: TJpegImage; bmp: Tbitmap; beginbmp: = 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; beginImage1: = 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; ---------- -------------------------------------------------- -----------

转载请注明原文地址:https://www.9cbs.com/read-6011.html

New Post(0)