Re-learning gdi+[99]: tgpimage (19)

Source: Internet
Author: User

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.

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.