Programming Windows with C# Chapter23 Metafiles

Slides:



Advertisements
Similar presentations
Graphics CS 121 Concepts of Computing II. What is a graphic? n A rectangular image. n Stored in a file of its own, or … … embedded in another data file.
Advertisements

SWE 423: Multimedia Systems Chapter 4: Graphics and Images.
Vector vs. Bitmap SciVis V
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
V Obtained from a summer workshop in Guildford County July, 2014
Working with Graphics. Objectives Understand bitmap and vector graphics Place a graphic into a frame Work with the content indicator Transform frame contents.
Graphics: Creating Images Chapter 8, Exploring the Digital Domain.
Dedicated Vector and Bitmap editing software.
SWHIG Seminar Ian Kim 1/18/12.  General overview of printing technology ◦ Background information:  Vector vs. raster graphics  How inkjet printers.
Statistical graphics for publication – easy ways to meet requirements for high resolution Jim Flewelling Growth Model Users Group February 11, 2008.
Simple Graphics. Graphics Used in PowerPoint, Web pages and others Basic Knowledge drawing change of colour, shape and others acquiring, video camera,
XP Practical PC, 3e Chapter 13 1 Working with Graphics.
Vector vs. Bitmap
Higher Computing Computer Systems S. McCrossan 1 Higher Grade Computing Studies 1. Data Representation Data Representation – Why do we use binary? simplicity,
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
Multimedia Elements II Graphics, Digital Video. UIT - Multimedia Production2 Multimedia Elements Multimedia elements include: Text Graphics Animation.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Information Processes and Technology Multimedia: Graphics.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
CS- 375 Graphics and Human Computer Interaction Lecture 1: 12/4/1435 Fundamental Techniques in Graphics Lecturer: Kawther Abas.
Chapter 4: Representation of data in computer systems: Images OCR Computing for GCSE © Hodder Education 2011.
Lecture 16 Image Document Formats. Bitmap vs. Vector Images Bitmaps do not generally.
Chapter 18 產生驗證碼. No Cache 防止在 JSP 或 SERVLET 中的輸出不被 BROWSER 保存在 CACHE 中.
Vector Graphics Multimedia Technology. Object Orientated Data Types Created on a computer not by sampling real world information Details are stored on.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Quiz # 1 Chapters 1,2, & 3.
Chapter 2 File Format Objectives (1 of 2) Identify the difference between vector based graphics and bitmap-based graphics Clarify 3 types of vector programs.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
BC ASSIGNMENT NO 5 HABEEB UR REHMAN HABEEB UR REHMAN.
Digital Graphics for Computer Games Pixels Types of Digital Graphics (Raster and Vector) Compression.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
RASTERIZING SHAPES IN PHOTOSHOP RASTERIZE: A process in Photoshop of converting a vector image into a bitmap (or raster) image VECTOR: A vector image is.
Guilford County SciVis V104.03
Mohammed AM Dwikat CIS Department Digital Image.
Vector vs. Bitmap. Vector Images Vector images (also called outline images) are images made with lines, text, and shapes. Test type is considered to be.
Chapter 14 Working with Graphics
Text and Images Key Revision Points.
Printing Petzold, Chapter 21
Multimedia Subject: Informatics of Technology II year
Image and Sound Representation
SVG & DOM Manipulation via Javascript
Computer Graphics Lecture 3 Computer Graphics Hardware
Chapter 13 Working with Graphics
Binary Notation and Intro to Computer Graphics
Introduction to Graphics
Vector vs. Bitmap.
CSI-447: Multimedia Systems
Lines, Curves, and Area Fill
IMAGES.
Bitmap vs. Vector.
Graphics and Multimedia
Chapter III, Desktop Imaging Systems and Issues: Lesson IV Working With Images
Chapter I Digital Imaging Fundamentals
Learning Intention I will learn how a computer stores graphics.
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Drawing Mouse and Keyboard Events Part A - Drawing
Introduction to Computer Graphics
6th Lecture – Rectangles and Regions, and intro to Bitmap Images
Data Representation.
Bitmap, Vector, Pixels, Resolution, Metadata.
CASE Tools Graphical User Interface Programming Using C#
Digital Media Dr. Jim Rowan ITEC 2110.
Terms 1 Terms 2 Terms 3 Terms 4 Terms 5 1pt 1 pt 1 pt 1pt 1 pt 2 pt
Chapter 2 Data Representation.
Lecture 4 - Introduction to Computer Graphics
Chapter 12 Graphics in Windows and the Web
Images and Bitmaps (in C#)
Lines, Curves and Area Fills
Presentation transcript:

Programming Windows with C# Chapter23 Metafiles Presenter: Yanmei Lan Partner: Pratyush Rai

Outline Introductions . Metafile and bitmap compared. Load metafile. Metafile properties. Create metafiles. Metafile Boundary control. Metafile record.

Introductions to Metafiles Metafiles are vector graphics just like bitmaps are raster graphics. A metafile consists of series of binary records that correspond to graphics function calls: to draw lines, curves, filled areas, and text. Metafiles are created by drawing programs. A metafile describes an image in terms of graphical drawing commands that can exist in a disk file or in memory. Metafiles can be stored in a disk or reside in memory.

Metafile and bitmap compared Similarities: 1, Both are used to described images. 2, Both can be stored in disk files . 3,Both inherit from the same abstract class – Image.

Differences Between Bitmap and Metafile 1, Paint programs create bitmaps; drawing program create metafiles, so metafiles describe a picture as a collection of function calls. 2,Bitmaps are from real-world images, but metafiles are constructed by human with computer program. 3, Metafile image can be scaled in size without loss of resolution, bitmaps don’t work that way. 4, A metafile can be converted to a bitmap easily, but converting bitmaps to metafiles is much more difficult.

Metafile Formats and Namespace There are two metafile formats: Windows Metafile – filename.wmf; Enhanced Metafile – filename.emf. Metafile and its related classes and enumeration are defined in the System.Drawing.Imaging namespace.

Class Hierarchy Object MarshalByRefObject Image(abstract) Bitmap Metafile

Loading Existing metafiles You can use FromFile method of Image class to load a metafile from disk: Image image = Image. FromFile(“MyMetafile.emf”); You can create a Metafile object from an existing metafile through Metafile Constructors: The constructors explicitly return an object of type Metafile: Metalfile mf = new Metafile(“MyMetafile.emf”); Metafile( String strFileName) Metafile( Stream stream)

Metafile Sizes and Rendering To display a metafile in its metrical size with the upper left corner at point(x, y): grfx.DrawImage(mf, x, y); To display a metafile stretched to the rectangle: grfx.DrawImage(mf, x, y, cx, cy ); To Display metafile in its pixel size, set page units to pixels and use: grfx.Drawimage(mf, x, y, mf.Width, mf.Height);

Load and Rendering Metafile

MetafileHeader Class MetafileHeader class encapsulate the metafile header that provide additional information about the metafile. You can obtain an object of MetafileHeader through static or nonstatic methods of Metafile class: MetafileHeader mh = mf.GetMetafileHeader ; Metatfileheader mh = Metafile. GetMetafileHeader( “MyPicture.emf);

Image Properties Metafile class inherit properties that describe the image. Image Properties (selection) Type Property Accessibility Size Size get int Width get int Height get float HorizontalResolution get float VerticalResolution get SizeF PhysicalDimension get

MetafileHeader Properties The MetafileHeader class has 10 read only properties that have information about the metafile, page 1106-1107. MetafileHeader Properties(selection) Type Property Accessibility MetafileType Type get int Version get int Metafilesize get Rectangle Bounds get float DpiX get float DpiY get

MetafileType Enumeration The Type property indicates the type of the metafile based on MetafileType enumerration. MetafileType Enumeration Member Value Invalid 0 Wmf 1 WmfPlaceable 2 Emf 3 emfPlusOnly 4 EmfPlusDual 5

Converting Metafiles to Bitmaps Using Bitmap constructor: Bitmap bm = new Bitmap(mf); Creating Bitmap object of particular size then obtain a graphics object to draw on the bitmap: grfx = Graphics.fromImage(bm); grfx.drawImage(mf, 0,0, cx, cy);

How to Create New Metafiles? Use some Metafile constructors with handle argument: Metafile(string strFileName, Intptr ipHdc); Metafile(Stream stream, IntPtr ipHdc); Example: Graphcs grfxVideo = CreateGraphics(); IntPtr ipHdc = grfxVideo.GetDC(); Metafile mf = new Metafile( “NewFile.emf”, ipHdc); grfxVideo.ReleaseDC(ipHdc); grfxVideo. Dispose(); Graphics grfxMetafile = Graphics. FromImage(mf); // add drawing commands in the metafile; grfxMetafile.Dispose();

Examples of Created metafiles

Continue You can also use a MemoryStream object to create the metafile in memory: readonly MemoryStream ms = new MemoryStream(); Metafile mf = new Metafile(ms, ipHdc);

The Metafile Boundary Rectangle You can control over the boundary rectangle of metafile by using other versions of the Metafile constructors with rectangle arguments: Metafile(string strFileName, Inptr ipHdc, Rectangle rect ); Metafile(string strFileName, Inptr ipHdc, RectangleF rectf); Metafile(string steFileName, Inptr ipHdc, rectangle rect, MetafileFrameUnit mfu); Metafile(sting strFileName, Intptr ipHdc, Rectanglef rectf,

MetafileFrameUnit Enumeration The MetafileFrameUnit enumeration indicated the units of the boundary rectangle: Member Value Description Pixel 2 Units of pixels Point 3 Units of 1/72 inch Inch 4 Units of inch Document 5 Units of 1/300 inch Millimeter 6 Units of millimeter GdiCompatible 7 Units of 1/100 millimeter

Metafile Create with Boundary Control

Metafiles and the Page Transform As you add graphics calls to the metafile, coordinates and size are adjusted based on any page transform that is set, see example.

Metafile with Different Transform

Setting Metafile Resolution When a metafile is created, its resolution is set through a device context handle. You can also create a metafile with resolution basing on the printer : PrinterSettings prnset = new PrinterSetting(); Graphics grfx = prnset.CreateMeasureGraphics();

Identify a Metafile Records Each Record of a Metafile is identified by a member of the EmfPlusRecordType enumeration: EmfPlusRecordType Enumeration(selection) Member Value Created version EmfPolyline 4 32-bit versions of Windows DrawLines 16379 Windows Forms program WmfPolyline 66341 32-bit program or Programs before 32-bit version

Create Shorter Metafiles Metafiles can be made shorter by constructors having EmfType arguments. Metafile Constrctors(selestion) Metafile(string strFilename, IntPtr ipHdc, EmfType et) Metafile(string strFileName, IntPtr ipHdc, EmfType et, string strDescription) Metagile(Stream stream, IntPtr ipHdc, EmfType et) Metafile(Intptr iphdc, EmfType et)

EmfType Enumeration EmfType Enumeration Member Value EmfOnly 3 EmfPlusOnly 4 EmfPlusDual 5