Introduction to GDI - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Introduction to GDI

Description:

clicking mouse in picturebox1 draws a red circle at that location and update the ... Avast, ye mateys! There be rough seas* ahead! Lubbers should steer to the shore. ... – PowerPoint PPT presentation

Number of Views:314
Avg rating:3.0/5.0
Slides: 31
Provided by: Rap46
Category:

less

Transcript and Presenter's Notes

Title: Introduction to GDI


1
Lecture 14 Introduction to GDI
2
Drawing Demo
picturebox1
txtSize
button1
button2
txtX
txtY
3
clicking mouse in picturebox1 draws a red circle
at that location and update the X and Y
textboxes. clicking the Draw Box button draws a
blue box of the specified Size at the X and Y
location.
4
positions box relative to upper left corner of
picturebox1
draws a blue box of specified size
5
gets mousepoint (position x and y)
displays mouse position
draws red circle of size 20
6
clears picturebox1
7
allows user to type in a different size
8
Graphics - Drawing Demo 2005
image goofy.jpg located inside Folder, Debug
picBox
txtFileName
btnInvert
btnGrayscale
btnLoad
9
Method to Read Image File
10
class Form1
declare img as a Bitmap
button event passes image by reference
. . .
11
Method Invert( )
inverts level of each color value of each pixel
12
Method Grayscale( )
sets all three color values to the average level
13
OpenFileDialog
Instead of requiring the user to type in a
filename, we can use the OpenFileDialog class to
bring up a file directory. This directory will
show the folder and files at the current level.
We can limit the files to those with a particular
set of extensions as shown. When the appropriate
file is selected, the picBox.Image can be
assigned a new Bitmap using the selected image
file.
14
Avast, ye mateys! There be rough seas
ahead! Lubbers should steer to the shore.
Proceed at yer own risk!
The following section is optional, for those who
are interested in learning how to make
pixel-level image operations faster (i.e.
practical).
such as C, C, C with pointers !!!!
15
Image Pixel Format
24 bit per pixel is 1 byte per color
scan line
red byte
blue byte
green byte
scan line must be a multiple of 4 bytes, so each
line is padded with between 0 and 3 bytes
16
Locking and Unlocking the Bitmap
pointer to the beginning of the first scan line
of the image
17
Pixel Operations
18
Fast Grayscale Method
19
Fast Invert Method
20
Form1 Button Events to Access ImgPro Methods
21
Disposing of Objects
It is important to call the Dispose( ) method if
you get a Graphics object by calling
CreateGraphics( ).
Alternatively, you can use the using construct,
which automatically calls Dispose( ) when an
object goes out of scope. using (Graphics g
this.CreateGraphics()) g.DrawLine(Pens.Black
, new Point(0, 0), new Point(3, 5))
which is equivalent to... Graphics g
this.CreateGraphics() try
g.DrawLine(Pens.Black, new Point(0, 0), new
Point(3, 5) finally if(g ! null)
((IDisposable)g).Dispose()
22
(No Transcript)
23
(No Transcript)
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com