This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Stdctrls, Extctrls;
Type
TForm1 = Class (Tform)
Opendialog1:topendialog;
Button1:tbutton;
Button2:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Formdestroy (Sender:tobject);
Procedure Formpaint (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, Gdipapi, Gdiputil;
Const
Openfilefilter =
' GDI + all can read picture format |*.png;*.jpg;*.gif;*.bmp;*.tif;*.emf;*.wmf;*.ico ' +
' |*.png|*.png ' +
' |*.jpg|*.jpg ' +
' |*.gif|*.gif ' +
' |*.bmp|*.bmp ' +
' |*.tif|*.tif ' +
' |*.EMF|*.EMF ' +
' |*.wmf|*.wmf ' +
' |*.ico|*.ico ';
ARREXT:ARRAY[0..4] of String = ('. png ', '. jpg ', '. gif ', '. bmp ', '. tif ');
ARRENCODENAME:ARRAY[0..4] of String =
(' Image/png ', ' image/jpeg ', ' image/gif ', ' image/bmp ', ' Image/tiff ');
Var
filename:string;
Img:tgpimage;
Procedure Tform1.formcreate (Sender:tobject);
Begin
IMG: = tgpimage.create;
Button1.caption: = ' open ';
Button2.caption: = ' save ';
End
Procedure Tform1.formdestroy (Sender:tobject);
Begin
Img. Free;
End
Procedure Tform1.formpaint (Sender:tobject);
Var
G:tgpgraphics;
Begin
If FileName <> ' then
Begin
G: = Tgpgraphics.create (Canvas.handle);
G.drawimage (IMG, Ten, IMG.) GetWidth, IMG. GetHeight);
G.free;
End
End
Procedure Tform1.button1click (Sender:tobject);
Begin
Opendialog1.filter: = Openfilefilter;
If Opendialog1.execute Then
Begin
FileName: = Opendialog1.filename;
Img. Free;
IMG: = tgpimage.create (FileName);
Repaint;
End
End
Procedure Tform1.button2click (Sender:tobject);
Var
Imgguid:tguid;
I:integer;
Begin
If FileName = ' Then
Begin
ShowMessage (' first to open file ');
Exit;
End
{One-time Save to 5 possible formats}
For I: = 0 to 4 do
Begin
Getencoderclsid (Arrencodename[i], imgguid); {Get format encoding first}
Img. Save (Changefileext (FileName, Arrext[i]), imgguid);
End
Beep;
End
End.