Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 17

Appendix A: Using Filled Shapes and Images

Overview

Creating Brushes and Filled Shapes Working with Bitmap Images

Lesson: Creating Brushes and Filled Shapes


Types of Brushes for Filled Shapes How to Create Solid and Texture Filled Shapes How to Create Hatch Filled Shapes How to Create a Gradient Filled Shape

How to Create a Path Gradient Filled Shape


How to Create Transparent Shapes Practice: Creating Brushes and Filled Shapes

Types of Brushes for Filled Shapes

Solid Brush

Texture Brush

Hatch Brush

Gradient Brush

Path Gradient Brush

How to Create Solid and Texture Filled Shapes

Use the Image class with the SolidBrush to create a solid filled shape

CodeExample

Use the Image class and the TextureBrush to create a texture pattern
CodeExample

How to Create Hatch Filled Shapes

The HatchBrush object creates a hatched line fill pattern The HatchBrush constructor takes three arguments

Hatch style Color of the hatch lines Color of the background

CodeExample

How to Create a Gradient Filled Shape


Use a gradient brush to fill a shape with a gradually changing color
Rectangle rect = new Rectangle(hPos, vPos, txtWidth, txtHeight); LinearGradientBrush lgBrush = new LinearGradientBrush(rect, Color.SeaGreen, Color.BlueViolet,LinearGradientMode.Horizontal);
e.Graphics.DrawString(myText, myFont, myBrush, hPos, vPos);

How to Create a Path Gradient Filled Shape

Use a path gradient brush to customize the way you fill a shape with gradually changing colors

CodeExample

How to Create Transparent Shapes


The alpha value of the color component indicates the transparency of the color To create semitransparent objects, set the alpha component of the color to a value less than 255

CodeExample

Practice: Creating Brushes and Filled Shapes


In this practice, you will

Create and modify brushes

Customize brushes

Begin reviewing the objectives for this practice activity

10 min

Lesson: Working with Bitmap Images


What Is a Bitmap Image? How to Load and Display an Image How to Crop and Scale Images How to Rotate, Skew, and Reflect Images

How to Create Thumbnail Images


Practice: Working with Bitmap Images

What Is a Bitmap Image?

Bitmap

A bitmap is an array of bits that specify the color of each pixel in a rectangular array of pixels Used for saving bitmaps in disk files BMP, GIF, JPEG, EXIF, PNG, TIFF

Graphic File Formats

Types of Graphic File Formats

How to Load and Display an Image


Use the Bitmap class for working with bitmap images To load and display a bitmap

Create a Bitmap object and pass the name of the image to the Bitmap constructor Pass that Bitmap object to the DrawImage method of a Graphics object

CodeExample

How to Crop and Scale Images


Use the DrawImage method of the Graphics class to crop and scale images One type of DrawImage takes two arguments, a Bitmap object and a Rectangle object

To crop and scale images specify the size of the rectangle as the desired image size

CodeExample

How to Rotate, Skew, and Reflect Images

To rotate, skew, and reflect an image

Specify destination points for the upper-left, upper-right, and lower-left corners of the original image
(100, 0) x (200, 20) is the destination for (0, 0)

(0, 0)

(0, 50)

(250, 30) is the destination for (0, 50)

(110, 100) is the destination for (100, 0)

CodeExample

How to Create Thumbnail Images


Create a thumbnail image by calling the GetThumbnailImage method of an Image object

Dim image = New Bitmap("Compass.bmp") Dim pThumbnail As Image = image.GetThumbnailImage(100, 100, Nothing, _ New IntPtr()) e.Graphics.DrawImage( _ pThumbnail, _ 10, _ 10, _ pThumbnail.Width, _ pThumbnail.Height)

Practice: Working With Bitmaps


In this practice, you will

Create a Bitmap object

Draw a Bitmap object


Draw scaled and skewed images

Begin reviewing the objectives for this practice activity

10 min

You might also like