Direct2d (1): First example

Source: Internet
Author: User
It should be Delphi 2009 that supports direct2d, but at that time I still used WINXP (not supported); now the test environment is win7 + delphixe.

Direct2d belongs to the DirectX family and is the successor of GDI and GDI +. It supports hardware acceleration and can interact with GDI, GDI + and d3d.
Other preliminary impressions are the use of directwrite and WIC technologies for text processing and image processing, as well as support layers.

The related units are direct2d. PAS and d2d1. Pas.
In direct2d. Pas, the simple implementation of direct2d by Delphi should also be mined from d2d1. Pas when more functions are required.

The direct2d. Pas unit mainly contains five classes: tdirect2dgraphicsobject, tdirect2dbrush, tdirect2dpen, tdirect2dfont, and tdirect2dcanvas,
Where tdirect2dgraphicsobject is the parent class of tdirect2dbrush, tdirect2dpen, and tdirect2dfont, which is generally not used independently,
Tdirect2dcanvas automatically creates and has three class objects: tdirect2dbrush, tdirect2dpen, and tdirect2dfont during instantiation. Therefore:
The main learning area is the tdirect2dcanvas class.

Looking at the source code in a rough way, we feel that the members of tdirect2dcanvas are very similar to those of TCanvas, because they inherit from tcustomcanvas, so they have many common features.

Example 1:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) Procedure formpaint (Sender: tobject ); procedure formresize (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses direct2d; Procedure tform1.formpaint (Sender: tobject); var d2dcanvas: tdirect2dcanvas; begin d2dcanvas: = tdirect2dcanvas. create (canvas, clientrect); d2dcanvas. begindraw; d2dcanvas. pen. color: = clred; d2dcanvas. pen. width: = 4; d2dcanvas. ellipse (50, 50, ClientWidth-50, ClientHeight-50); d2dcanvas. enddraw; d2dcanvas. free; end; Procedure tform1.formresize (Sender: tobject); begin invalidate; 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.