Gdiplus [2]: Obtain the drawing surface (graphics)

Source: Internet
Author: User
Graphics (canvas in The VCL system) has four methods to obtain graphics:

1. Get through the window handle;
2. Get it through canvas. handle in the window;
3. Get the togpgraphics method added to some VCL objects through gdiplus using helper technology;
4. Obtain the image object.

In this example:


Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure submit (Sender: tobject ); end; var form1: tform1; implementation {$ R *. DFM} uses gdiplus, gdiplushelpers; // obtain the javastform1.button1click (Sender: tobject) from the window handle; var graphics: igpgraphics; pen: igppen; begin graphics: = tgpgraphics. create (handle); pen: = tgppen. create (tgpcolor. red, 2); graphics. drawellipse (pen, 20, 10,150, 40); end; // obtain igpgraphicsprocedure tform1.button2click (Sender: tobject) from HDC; var graphics: igpgraphics; pen: igppen; begin graphics: = tgpgraphics. create (canvas. handle); pen: = tgppen. create (tgpcolor. green, 2); graphics. drawellipse (pen, 20, 40,150, 40); end; // use the togpgraphics method added to the canvas by gdiplushelpers to obtain javastform1.button3click (Sender: tobject); var graphics: igpgraphics; pen: igppen; begin graphics: = canvas. togpgraphics; pen: = tgppen. create (tgpcolor. blue, 2); graphics. drawellipse (pen, 20, 70,150, 40); end; // create igpgraphicsprocedure tform1.button4click (Sender: tobject) from the image; var graphicsimg: igpgraphics; pen: igppen; Image: igpimage; begin image: = tgpbitmap. create (152, 42); graphicsimg: = tgpgraphics. create (image); pen: = tgppen. create (tgpcolor. fuchsia, 2); graphicsimg. drawellipse (pen, 0, 0, image. width-2, image. height-2); canvas. togpgraphics. drawimage (image, 20,100); end.
 
  
 
Related Article

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.