Raunarska grafika GDI Graphics Device Interface Plus Metafiles

  • Slides: 10
Download presentation
Računarska grafika GDI+ (Graphics Device Interface Plus)

Računarska grafika GDI+ (Graphics Device Interface Plus)

Metafiles in GDI+ • GDI+ provides the Metafile class so that you can record

Metafiles in GDI+ • GDI+ provides the Metafile class so that you can record and display metafiles. A metafile, also called a vector image, is an image that is stored as a sequence of drawing commands and settings. The commands and settings recorded in a Metafileobject can be stored in memory or saved to a file or stream. • GDI+ can display metafiles that have been stored in the following formats: ▫ Windows Metafile (WMF) ▫ Enhanced Metafile (EMF) ▫ EMF+ �EMF+ Only (GDI+ only) �EMF+ Dual (GDI & GDI+ - dual records) *GDI+ can record metafiles in the EMF and EMF+ formats, but not in the WMF format.

Metafiles in GDI+ • Metafiles contain information about how an image was created -

Metafiles in GDI+ • Metafiles contain information about how an image was created - including lists of graphics operations - rather than storing the image in pixel format. Graphics operations in a metafile are stored as records, which can be controlled (recorded and played back) individually. • The Metafile class provides about 40 overloaded forms of its constructor. • Loading and viewing a metafile is similar to viewing a bitmap. An application can load a metafile from a stream, string, or Int. Ptr instance with different formats and locations. The simplest way to load and view a metafile is to pass the file name in the Metafile constructor and call Draw. Image.

Metafile Class • The Metafile class is derived from the Image class has no

Metafile Class • The Metafile class is derived from the Image class has no methods and properties beside those inherited from the Image class. • the Metafile class provides a long list of overloaded constructor. It also provides three methods: ▫ Get. Henh. Metafile �returns a window handle to a metafile ▫ Get. Metafile. Header �which has five overloaded forms, returns a metafile header in the form of a Metafile. Header object. ▫ Play. Record. �plays (reads and displays) an extended metafile.

Metafile Class • Metafile( string filename ) ▫ filename �A String that represents the

Metafile Class • Metafile( string filename ) ▫ filename �A String that represents the file name from which to create the new Metafile. • Metafile( string file. Name, Int. Ptr reference. Hdc ) ▫ file. Name �A String that represents the file name of the new. Metafile. ▫ reference. Hdc �A Windows handle to a device context.

Example Graphics g = e. Graphics; g. Clear(this. Back. Color); Int. Ptr hdc =

Example Graphics g = e. Graphics; g. Clear(this. Back. Color); Int. Ptr hdc = g. Get. Hdc(); Metafile metafajlic = new Metafile(@"C: Documents and SettingsOgnjenDesktopRGtest. emf", hdc); Graphics g 1 = Graphics. From. Image(metafajlic); g 1. Smoothing. Mode = Smoothing. Mode. High. Quality; Rectangle kvadratic = new Rectangle(0, 0, 200); g 1. Fill. Rectangle(Brushes. Green, kvadratic); kvadratic. Y += 110; Linear. Gradient. Brush cetkica = new Linear. Gradient. Brush(kvadratic, Color. Red, Color. Blue, 45. 0 f); g 1. Fill. Ellipse(cetkica, kvadratic);

Example kvadratic. Y += 110; g 1. Draw. String("Računarska grafika, I. Sarajevon. Meta. File

Example kvadratic. Y += 110; g 1. Draw. String("Računarska grafika, I. Sarajevon. Meta. File test", new Font("Verdana", 20), cetkica, 200, String. Format. Generic. Typographic); g. Release. Hdc(hdc); metafajlic. Dispose(); metafajlic = new Metafile(@"C: Documents and SettingsOgnjenDesktopRGtest. emf"); g. Draw. Image(metafajlic, 0, 0); metafajlic. Dispose(); g 1. Dispose();

Example Bitmap slicica = new Bitmap(616, 310); g 1 = Graphics. From. Image(slicica); g

Example Bitmap slicica = new Bitmap(616, 310); g 1 = Graphics. From. Image(slicica); g 1. Smoothing. Mode = Smoothing. Mode. High. Quality; kvadratic = new Rectangle(0, 0, 200); g 1. Fill. Rectangle(Brushes. Green, kvadratic); kvadratic. Y += 110; g 1. Fill. Ellipse(cetkica, kvadratic); kvadratic. Y += 110; g 1. Draw. String("Računarska grafika, I. Sarajevon. Meta. File test", new Font("Verdana", 20), cetkica, 200, String. Format. Generic. Typographic);

Example slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. bmp", Image. Format. Bmp); slicica. Save(@"C: Documents and

Example slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. bmp", Image. Format. Bmp); slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. jpg", Image. Format. Jpeg); slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. gif", Image. Format. Gif); slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. png", Image. Format. Png); slicica. Save(@"C: Documents and SettingsOgnjenDesktopRGtestic. emf", Image. Format. Emf); g. Draw. Image(slicica, 0, 350); g 1. Dispose(); g. Dispose();

Example

Example