Document 15063144

advertisement
Mata kuliah : M0874 – Programming II
Tahun
: 2010
Graphics and Multimedia
Session 13
Outline Materi
•Introduction
•Graphics Contexts and Graphics Objects
•Drawing in C#
•Introduction to Multimedia
Bina Nusantara University
3
Introduction
•C# supports graphics that enable programmers to
enhance their Windows applications visually.
•Graphics, video, sound, and printing are the
hallmarks of a traditional rich client on the Microsoft
Windows operating system.
Bina Nusantara University
4
Graphics Contexts and Graphics Objects
•A C# graphics context represents a drawing surface that enables drawing on the
screen.
•A Graphics object manages a graphics context by controlling how information is
drawn.
•Graphics object contain methods for drawing, font manipulation, color
manipulation and other graphics-related actions.
•Every windows application that derives from class System.Windows.Forms.Form
inherits a virtual OnPaint event handler where most graphics operations are
performed.
5
Graphics Contexts and Graphics Objects
•The argument to the OnPaint method include a
PaintEventArgs object from which we can obtain a
Graphics object for the control.
•The OnPaint mehtod triggers the Control’s Paint event.
•To override the inherited OnPaint mehtod, use the
following method definition:
protected override void OnPaint ( PaintEventArgs e )
•Extract the incoming Graphics object from the
PaintEventArgs argument:
Grapics graphicsObject = e.Graphics;
Bina Nusantara University
6
Graphics Contexts and Graphics Objects
Bina Nusantara University
7
Creating a Pen
Example, create red pen that is 5 pixels wide as
follows:
Bina Nusantara University
8
Creating a Pen
•Once a Pen object has been created other properties may
be changed.
•Example, the DashStyle property can be modified to change
the style of line (i.e Dash, DashDot, DashDotDot, Dot, Solid
or Custom).
•Properties such as the color and width may similarly be
changed after a Pen has been created:
Bina Nusantara University
9
Drawing Lines
•Lines are drawn in C# using the DrawLine()
method of the Graphics Object.
Bina Nusantara University
10
Drawing Squares and Rectangles
Bina Nusantara University
11
Drawing Ellipses and Circles
Bina Nusantara University
12
Drawing Text
Bina Nusantara University
13
Introduction to Multimedia
•C# offers many convenient ways to include images
and animations in programs.
•Multimedia programming is an entertaining and
innovative field, but one that presents many
challenges.
•Multimedia applications demand extraordinary
computing power.
Bina Nusantara University
14
Multimedia
•Using Visual Studio .NET and C#, programmers
can create applications that use components such
as Windows Media Player and Microsoft Agent.
•The Windows Media Player allows programmers to
create applications that can play multimedia files.
•Microsoft Agent is a technology that allows
programmers to include interactive animated
characters in their applications.
Bina Nusantara University
15
References
•http://www.techotopia.com/index.php/Drawing_Gra
phics_in_C_Sharp
•http://www.vcskicks.com/csharp_animated_gif.php
Bina Nusantara University
16
Download