Gdiplus [50]: image (2) about create

Source: Internet
Author: User
The create method provided by the igpimage class:
Image: = tgpimage. create (file (or stream), Boolean); // The Boolean value defaults to false. If it is true, the file (or stream) is used) embedded color management information for color correction. {Example 1: Create from file} var graphics: igpgraphics; Image: igpimage; begin image: = tgpimage. create ('C: \ gdiplusimg \ grapes.jpg '); graphics: = tgpgraphics. create (handle); graphics. drawimage (image, 10, 10); end; {Example 2: Create from stream (istream)} const Path = 'C: \ gdiplusimg \ grapes.jpg '; var graphics: igpgraphics; image: igpimage; stream: istream; {ActiveX unit in istream declaration} begin stream: = tstreamadapter. create (tfilestream. create (path, fmopenread), soowned); Image: = tgpimage. create (Stream); graphics: = tgpgraphics. create (handle); graphics. drawimage (image, 10, 10); end;
 

The create method provided by the igpbitmap class:

// 1. as the successor of igpimage, igpbitmap can also use the igpimage creation method. In addition: // 2. you can specify the width, height, and pixel format. The default pixel format is pixelformat32bppargb: var bitmap: igpbitmap; begin bitmap: = tgpbitmap. create (100,100); showmessage (inttostr (bitmap. pixelformat); {2498570} bitmap: = tgpbitmap. create (100,100, pixelformat32bppargb); showmessage (inttostr (bitmap. pixelformat); {2498570} end; // 3. you can specify the width, height, and graphics (with the resolution): var graphics: igpgra Phics; bitmap: igpbitmap; BX, by, GX, GY: single; begin graphics: = tgpgraphics. create (canvas. handle); bitmap: = tgpbitmap. create (100,100, graphics); Bx: = bitmap. horizontalresolution; by: = bitmap. verticalresolution; GX: = graphics. dpix; Gy: = graphics. dpiy; showmessagefmt ('% G: % G; % G: % G', [BX, by, GX, Gy]); {96: 96; 96: 96} end; // 4. create a pixel acquisition from another image: var graphics: igpgraphics; bitmaptmp, bitmap: igpbitmap; Brush: igpsolidbrush; rect: tgprect; bitmapdata: tgpbitmapdata; begin bitmaptmp: = tgpbitmap. create (16, 16); graphics: = tgpgraphics. create (bitmaptmp); brush: = tgpsolidbrush. create (0); brush. color: = $ ffff0000; graphics. fillrectangle (brush, 0, 0, 8, 16); brush. color: = $ ff0000ff; graphics. fillrectangle (brush, 8, 0, 8, 16); rect. initialize (0, 0, bitmaptmp. width, bitmaptmp. height); bitmapdata: = Bi Tmaptmp. lockbits (rect, [imagelockmoderead], bitmaptmp. pixelformat); bitmap: = tgpbitmap. create (100,100, 4, pixelformat32bppargb, bitmapdata. scan0); graphics: = tgpgraphics. create (handle); graphics. drawimage (bitmap, 10, 10); bitmaptmp: = tgpbitmap. create (16, 16); end; // 5. create from hbitmap: var graphics: igpgraphics; bitmap: igpbitmap; bit: tbitmap; begin bit: = tbitmap. create; bit. loadfromfile ('C: \ gdipl Usimg \ bird.bmp '); bitmap: = tgpbitmap. create (bit. handle, bit. palette); bit. free; graphics: = tgpgraphics. create (handle); graphics. clear ($ ffffffff); graphics. drawimage (bitmap, 10, 10); end; // 6. create from hicon: var graphics: igpgraphics; bitmap: igpbitmap; begin bitmap: = tgpbitmap. create (application. icon. handle); graphics: = tgpgraphics. create (handle); graphics. drawimage (bitmap, 10, 10); end; // 7. from the resource file Create an image (it seems that it can only be BMP) (assuming you have added a resource image named bitmap_1): var graphics: igpgraphics; bitmap: igpbitmap; begin bitmap: = tgpbitmap. create (hinstance, 'bitmap _ 1'); graphics: = tgpgraphics. create (handle); graphics. drawimage (bitmap, 10, 10); end; // 8. it can also be created through tbitmapinfo. // 9. establish directdrawsurface7; is this the starting point for combining GDI + with DirectX? Find time to learn.
 

The create method provided by the igpmetafile class:

// 1. as the successor of igpimage, igpmetafile can also be created using the igpimage method: var graphics: igpgraphics; Metafile: igpmetafile; begin Metafile: = tgpmetafile. create ('C: \ gdiplusimg \ samplemetafile. emf'); graphics: = tgpgraphics. create (handle); graphics. drawimage (Metafile, 10, 10); end; // 2. create and draw from a file (if the file does not exist, create it and overwrite it; HDC must be specified at the same time): var graphicsmeta, graphics: igpgraphics; Metafile: igpmetafile; pen: igppen; begin Metafile: = tgpmetafile. create ('C: \ gdiplusimg \ test. emf', canvas. handle); graphicsmeta: = tgpgraphics. create (Metafile); pen: = tgppen. create ($80ff0000); graphicsmeta. drawrectangle (pen, 0, 0, 50, 30); graphicsmeta: = nil; {This ends the drawing} graphics: = tgpgraphics. create (handle); graphics. drawimage (Metafile, 10, 10); end; // 3. you can specify the file size when creating a file. It is best to specify the size unit at the same time; otherwise, the default unit is metafileframeunitgdivar graphicsmeta, graphics: igpgraphics; Metafile: igpmetafile; pen: igppen; rect; begin rect. initialize (0, 0,100,100); Metafile: = tgpmetafile. create (canvas. handle, rect, metafileframeunitpixel); graphicsmeta: = tgpgraphics. create (Metafile); pen: = tgppen. create ($80ff0000); graphicsmeta. drawrectangle (pen, 0, 0, 50, 30); graphicsmeta: = nil; text: = format ('% d, % d', [Metafile. width, Metafile. height]); graphics: = tgpgraphics. create (handle); graphics. drawimage (Metafile, 10, 10); end; // 4. you can specify the metadata file type: var graphicsmeta, graphics: igpgraphics; Metafile: igpmetafile; pen: igppen; begin Metafile: = tgpmetafile. create (canvas. handle, emftypeemfplusonly); graphicsmeta: = tgpgraphics. create (Metafile); pen: = tgppen. create ($80ff0000); graphicsmeta. drawrectangle (pen, 0, 0, 50, 30); graphicsmeta: = nil; text: = format ('% d, % d', [Metafile. width, Metafile. height]); graphics: = tgpgraphics. create (handle); graphics. drawimage (Metafile, 10, 10); end; {There are three types of metafiles:} // all records in the emfonly file are EMF records, which can be displayed through GDI or GDI +. // all records in the emfplusonly file are EMF + records, which can be displayed through GDI +, but not through GDI. // all records in the emfplusdual file are in dual copies (EMF + and EMF) and can be displayed through GDI or GDI +. // 5. you can write the description text var graphicsmeta, graphics: igpgraphics; Metafile: igpmetafile; pen: igppen; begin Metafile: = tgpmetafile. create (canvas. handle, emftypeemfplusonly, 'description _ 123 '); graphicsmeta: = tgpgraphics. create (Metafile); pen: = tgppen. create ($80ff0000); graphicsmeta. drawrectangle (pen, 0, 0, 50, 30); graphicsmeta: = nil; graphics: = tgpgraphics. create (handle); graphics. drawimage (Metafile, 10, 10); end; // there are still many examples of the Creation parameters of the Metafile, basically the combination of these things.
 

There are also some from... functions that are the same as create:

Image := TGPImage.FromFile();Image := TGPImage.FromStream();Bitmap := TGPBitmap.FromFile();Bitmap := TGPBitmap.FromStream();Bitmap := TGPBitmap.FromDirectDrawSurface7();Bitmap := TGPBitmap.FromBitmapInfo();Bitmap := TGPBitmap.FromHBitmap();Bitmap := TGPBitmap.FromHIcon();Bitmap := TGPBitmap.FromResource();Metafile := TGPMetafile.FromFile();Metafile := TGPMetafile.FromStream();
 

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.