100 likes | 320 Views
Računarska grafika. GDI+ ( Graphics Device Interface Plus). Metafiles in GDI+.
E N D
Računarska grafika GDI+ (Graphics Device Interface Plus)
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 - 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 IntPtr 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 DrawImage.
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: • GetHenhMetafile • returns a window handle to a metafile • GetMetafileHeader • which has five overloaded forms, returns a metafile header in the form of a MetafileHeader object. • PlayRecord. • plays (reads and displays) an extended metafile.
Metafile Class • Metafile( string filename) • filename • A String that represents the file name from which to create the new Metafile. • Metafile( string fileName, IntPtrreferenceHdc) • fileName • A String that represents the file name of the newMetafile. • referenceHdc • A Windows handle to a device context.
Example Graphics g = e.Graphics; g.Clear(this.BackColor); IntPtrhdc = g.GetHdc(); Metafile metafajlic = new Metafile(@"C:\Documents and Settings\Ognjen\Desktop\RG\test.emf", hdc); Graphics g1 = Graphics.FromImage(metafajlic); g1.SmoothingMode = SmoothingMode.HighQuality; Rectangle kvadratic = new Rectangle(0, 0, 200, 200); g1.FillRectangle(Brushes.Green, kvadratic); kvadratic.Y += 110; LinearGradientBrushcetkica = new LinearGradientBrush(kvadratic, Color.Red, Color.Blue, 45.0f); g1.FillEllipse(cetkica, kvadratic);
Example kvadratic.Y += 110; g1.DrawString("Računarskagrafika, I.Sarajevo\nMetaFile test", new Font("Verdana", 20), cetkica, 200, 200, StringFormat.GenericTypographic); g.ReleaseHdc(hdc); metafajlic.Dispose(); metafajlic = new Metafile(@"C:\Documents and Settings\Ognjen\Desktop\RG\test.emf"); g.DrawImage(metafajlic, 0, 0); metafajlic.Dispose(); g1.Dispose();
Example Bitmap slicica = new Bitmap(616, 310); g1 = Graphics.FromImage(slicica); g1.SmoothingMode = SmoothingMode.HighQuality; kvadratic = new Rectangle(0, 0, 200, 200); g1.FillRectangle(Brushes.Green, kvadratic); kvadratic.Y += 110; g1.FillEllipse(cetkica, kvadratic); kvadratic.Y += 110; g1.DrawString("Računarskagrafika, I.Sarajevo\nMetaFile test", new Font("Verdana", 20), cetkica, 200, 200, StringFormat.GenericTypographic);
Example slicica.Save(@"C:\Documents and Settings\Ognjen\Desktop\RG\testic.bmp", ImageFormat.Bmp); slicica.Save(@"C:\Documents and Settings\Ognjen\Desktop\RG\testic.jpg", ImageFormat.Jpeg); slicica.Save(@"C:\Documents and Settings\Ognjen\Desktop\RG\testic.gif", ImageFormat.Gif); slicica.Save(@"C:\Documents and Settings\Ognjen\Desktop\RG\testic.png", ImageFormat.Png); slicica.Save(@"C:\Documents and Settings\Ognjen\Desktop\RG\testic.emf", ImageFormat.Emf); g.DrawImage(slicica, 0, 350); g1.Dispose(); g.Dispose();