Images and Bitmaps (in C#)

Slides:



Advertisements
Similar presentations
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Advertisements

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.
2.01 Understand Digital Raster Graphics
PictureBox, Timer, Resources. Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that.
How Images are Represented Bitmap images (Dots used to draw the image) Monochrome images 8 bit grey scale images 24 bit colour Colour lookup tables Vector.
Raster vs Vector and Image Resolution By Josh Gallagan.
Working with Graphics. Objectives Understand bitmap and vector graphics Place a graphic into a frame Work with the content indicator Transform frame contents.
Prepared by George Holt Digital Photography BITMAP GRAPHIC ESSENTIALS.
XP Tutorial 7 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Working with Graphics Tutorial 7.
Dean Pentcheff NHMLAC MBPC/Crustacea 17 April 2006.
COMP Bitmapped and Vector Graphics Pages Using Qwizdom.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Simple Graphics. Graphics Used in PowerPoint, Web pages and others Basic Knowledge drawing change of colour, shape and others acquiring, video camera,
Pixels, Resolution and File Types Using Digital Media in the Classroom START.
 Scaling an image is resizing the image in a graphic editing software so it is the proper size before adding it to a site.  Important NOTE: If you insert.
Chapter 11 Bitmaps, Icons and Cursors. Copyright 2006 © Thomas P. Skinner2 Background Bitmaps are easy in.NET. Two kinds of graphics: 1.Vector 2.Bitmaps.
Section 8.1 Create a custom theme Design a color scheme Use shared borders Section 8.2 Identify types of graphics Identify and compare graphic formats.
Graphics in HTML. Graphics  Question: How does a web page include graphics?  Are the graphics included in the HTML file or separate files?
Graphics. Graphic is the important media used to show the appearance of integrative media applications. According to DBP dictionary, graphics mean drawing.
Graphics and Images Graphics and images are both non-textual information, that can be displayed and printed. These images may appear on screen as well.
By Courtney Field Creative digital graphics. Types of graphics and examples There are a number of different types of graphics file formats. Each type.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Graphics & Images What File Format Do I Use?. Graphics & Images …..are visual images presented on some form of media (drawings, print, web, digital video)
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.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
Photoshop CS6 – Nelson Unit 3: Photoshop CS6. Objectives Define photo editing software Start Photoshop and view the workspace Use the Zoom tool and the.
8th Lecture – Intro to Bitmap or Raster Images
Section 8.1 Section 8.2 Create a custom theme Design a color scheme
2.01 Understand Digital Raster Graphics
Multimedia Subject: Informatics of Technology II year
2.01 Understand Digital Raster Graphics
Objective % Describe digital graphics production methods.
Understanding Web Graphics
Exploring Computer Science - Lesson 3-4
Images.
Images.
Chapter 3 Image Files © 2013 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website,
4 Importing Graphics Desktop Publishing: Chapter 4
Introduction to Graphics
Exploring Computer Science - Lesson 3-4
Vector vs. Bitmap.
Pixel, Resolution, Image Size
Inserting and Working with Images
2.01 Understand Digital Raster Graphics
Lines, Curves, and Area Fill
Objective 8.02 Apply Procedures to Create Picture Boxes using Images.
2.01 Investigate graphic image design.
Bitmap vs. Vector.
Chapter 3 Image Files © 2017 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Exploring Computer Science - Lesson 3-4
Programming Windows with C# Chapter23 Metafiles
Graphics and Multimedia
Microprocessor and Assembly Language
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Introduction to Computer Graphics
Graphics Basic Concepts.
6th Lecture – Rectangles and Regions, and intro to Bitmap Images
Screen and Image Resolution
2.01 Understand Digital Raster Graphics
MED 2001 Advanced Media Production
Images.
Images.
Objective % Describe digital graphics production methods.
2.01 Investigate graphic image design.
Images.
2.01 Understand Digital Raster Graphics
2.01 Investigate graphic image design.
2.01 Investigate graphic image design.
Lines, Curves and Area Fills
Presentation transcript:

Images and Bitmaps (in C#) Li-Chih Hsu With a few modifications by Matthew Miling Advanced Windows Programming

Contents Overview – Images and Bitmaps Fundamental Windows Classes System.Drawing.Image System.Drawing.Bitmap Other Image/Bitmap Types

Overview – Images and Bitmaps In computers, two types of graphics Vector - graphics made of lines and curves - fonts, CAD programs, Photoshop Raster - rectangular arrays called bitmaps - almost all internet images are bitmaps

Bitmap Support Overview The System.Drawing namespace has two classes, named Image and Bitmap. The Bitmap class and Metafile class are derived from Image class. Bitmap file formats A bitmap has a particular height and width measured in pixels. A bitmap also has a particular color depth,which is the number of bits per pixel(bpp).

System.Drawing.Image Hierarchy Object MarshalByRefObject Image Used to declare an image object: Image image; Used to load various bitmap formats .bmp .gif .jpg .png .tiff .exif .wmf .emf

Loading and Drawing Three different methods: Obtain an image from a bitmap file on disk: Image.FromFile(string filename) Obtain an image from a valid bitmap stream Image.FromStream(System.IO.Stream stream) Obtain a bitmap object using a Win32 GDI bitmap Image.FromHbitmap(System.IntPtr hbitmap)

Image Information Image properties Type Property Accessiblity Description Size Size get int Width get int Height get float HorizontalResolution get In dots per inch float VerticalResolution get In dots per inch

Drawing the image Use the OnPaint handler to initiate the draw Use the DrawImage() method from the System.Drawing.Graphics class to draw the actual image Sample Code protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawImage(image); }

Graphics.DrawImage() Currently, 30 different instances exist for the DrawImage() method Appropriate method is application specific void DrawImage(Image image) void DrawImage(Image image, int x, int y) void DrawImage(Image image, int x, int y, int cx, int cy) void DrawImage(Image image, Rectangle rect) Example 1,2

Metrics vs. Pixels Images by default draw with metrics for image device independence a 3 inch image is 3 inches wide on monitor and printer relies heavily on embedded resolution (image dpi) Pixels are a straightforward mapping of bits onto the screen One pixel (dot) on screen = one location on bitmap Image with high dpi will be smaller than image with low dpi, but will have better visual quality

Rectangular fitting Shows the different uses of rectangular fitting Use DrawImage() with different arguments for different effects Examples 3, 4

Image Reflection If we specify a negative width, the image is flipped around the vertical axis – it’s mirror image. Sample Code: grfx.DrawImage(image cx/2,cy/2, cxImage,cyImage); grfx.DrawImage(image cx/2,cy/2, -cxImage,cyImage); grfx.DrawImage(image cx/2,cy/2, cxImage, -cyImage); grfx.DrawImage(image cx/2,cy/2, -cxImage,-cyImage); example5

Rotate and Shear These two methods effectively translate,scale,shear,rotate an image into a parallelogram. Void DrawImage(Image image, Point[ ] apt) Void DrawImage(Image image, PointF[ ] aptf) The array argument must contain exactly three points Apt[0] = destination of upper left corner of image. Apt[1] = destination of upper right corner of image. Apt[2] = destination of lower left corner of image. See example 6

Partial image display Ability to draw only a portion of the image we would like to see Let you specify a rectangular subsection of the bitmap to display. Example code: new Rectangle(0, 0 ,image.Width, image.Height) See example 7

Drawing on the image Ability to overlap text onto the image To draw on an image , we need to obtain a Graphics object that refer to the image. Use the DrawString() method Cannot use indexed bitmaps! (i.e. gifs) Example 8

Thumbnail The GeThumbnailImage method is intend to be used to create a thumbnail of an image, which is a smaller version of the image that an application can use to convey the contents of the image while saving time and space. Image GEtThumbnailImage(int cx,int cy,Image GetThumbnailImageAbort gtia,InPtr pData); See example 9

System.Drawing.Bitmap Derives from Image For applications with images that do more than just draw Allow developer/user to manipulate graphics at the bit level Icons, Animation, Image List, Picturebox

System.Drawing.Bitmap Image has no constructors Bitmap has 12 constructors: Bitmap(string strFilename) Bitmap(Stream stream) Bitmap(Image image) Bitmap(Image image, Size size) Bitmap(int cx, int cy)

Bitmap Example Begin with two bitmaps for text length We see text placed on a bitmap Example 10 Try different dpi!

Binary Resources Embed icons and cursors within the software Whenever you create a bitmap, a cursor,or an icon file you want to use as resource. In visual C#.NET,when you select any bitmap,icon, or cursor file in solution Explorer that is part of a project, you’ll see a properties window for the file. Change the Build Action property to Embedded Resource. Example 11

Animation Uses a Timer data type to load a new image each tick Loads a set of bitmaps into an array for quick run-through See page 530 for ‘Wink’ example

Image List An image list is essentially just a flexible array of Image objects with the same size and color format. To create an object: ImageList imglst = new ImageList(); To add Image object to the image list: Imglist.Images.Add(image); Number of images in an imageList imglst.Images.Count;

Image List (cont.) To return to image object imglst.Images[2]; ImageList.imageCollection Methods bool contains(image image) Int IndexOf(image image) void RemoveAt(int index) void Clear()

Image List (cont.) Draw Methods void Draw(Graphics grfx, Point pt,int index) void Draw(Graphics grfx, int x, int y,int index) void Draw(Graphics grfx, int x,int y, int cx,int cy,int index)

Picture Box Another image-related control Descended from Control Properties Type property Accessibility image image get/set BorderStyle borderStyle get/set PictureBoxSizeMode SizeMode get/set

Question?