Logo
PREGNANCY
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Phone

Raster Graphics - The Bitmap Class Hierarchy

3/28/2011 9:45:03 AM
As you’ll recall, you can display a bitmap in one of two ways: using the Image element or creating an ImageBrush. The Source property of the Image element and the ImageSource property of the ImageBrush are both of type ImageSource, a class occupying a very fundamental place in the region of the Silverlight class hierarchy devoted to bitmaps:
Object
DependencyObject (abstract)
ImageSource (abstract)
BitmapSource (abstract)
BitmapImage
WriteableBitmap

ImageSource has only one descendent class and defines nothing public on its own, so it might seem a little superfluous. That’s true in Silverlight but not in the Windows Presentation Foundation, where ImageSource is a parent to classes that define images derived from vector graphics as well as those involving raster graphics.

The remaining three classes are all defined in the System.Windows.Media.Imaging namespace.

BitmapSource defines two public get-only properties and one method:

  • A PixelWidth property of type int.

  • A PixelHeight property of type int.

  • A SetSource method that has one argument of type Stream.

That Stream argument can be a file stream, a network stream, or a memory stream of some sort. But the Stream must provide bitmap data in either the JPEG or PNG file format. Once a bitmap has been created, it has a fixed size that cannot be changed.

The BitmapImage class expands on the functionality of BitmapSource by letting you reference a bitmap with a URI. BitmapImage defines the following:

  • A constructor that accepts an argument of type Uri.

  • A UriSource property of type Uri.

  • A CreateOptions property.

  • Three events that let you track downloading progress, and report upon success or failure

The CreateOptions property is of type CreateOptions, an enumeration with three members: None, DelayCreation, and IgnoreImageCache. The default is DelayCreation, which doesn’t start loading an image until it’s actually needed for rendering. The IgnoreImageCache is useful when a program knows that a previously loaded image has become invalid. You can combine DelayCreation and IgnoreImageCache with the C# bitwise OR operator.

By combining the features of BitmapSource and BitmapImage, the BitmapImage class lets you load a bitmap in JPEG or PNG format using either a Stream object or a Uri object. There is no facility to save bitmaps.

The WriteableBitmap class itself continues this trend. Taken by itself, WriteableBitmap does not including any facility to save bitmaps. However, the WriteableBitmap class does give you access to all the pixels that define the bitmap. Only one pixel format is supported, where each pixel is a 32-bit value. You can obtain the pixel bits from an existing bitmap, or set new pixel bits on a WriteableBitmap to define the image. Access to these pixel bits allows you a great deal of flexibility in how you save or load bitmaps. You can provide your own bitmap “encoder” to save pixel bits in a particular bitmap format, or your own “decoder” to access a file of a particular format and convert to the uncompressed pixel bits.

WriteableBitmap also provides a facility to “draw” images on the bitmap based on Silverlight elements. Although you can indeed draw Button elements and SliderShape. In other words, WriteableBitmap allows you to convert a vector drawing into a raster image. elements on a bitmap, it’s most common to use elements that derive from

Here are the constructors, methods, and property defined by WriteableBitmap:

  • A constructor that accepts a UIElement and a transform.

  • A constructor that accepts a pixel width and height.

  • A constructor that accepts a BitmapSource object.

  • A Render method that accepts a UIElement and a transform.

  • An Invalidate method to update bitmap visuals.

  • A property named Pixels of type int array.

Keep in mind that WriteableBitmap derives from BitmapSource rather than BitmapImage, so there is no facility in WriteableBitmap to load a bitmap from a URI. However, you can load a BitmapImage object from a URI and then create a WriteableBitmap from that using the third constructor I’ve listed.

WriteableBitmap lets you put images on the bitmap using two techniques:

  • By rendering the visuals of any UIElement on the bitmap.

  • By directly manipulating the pixel bits.

You can combine these techniques in whatever manner you want.

In addition, Windows Phone 7 provides several subsidiary methods that provide you with alternative ways to load JPEG files and to save them:

  • A static PictureDecoder.DecodeJpeg method in the Microsoft.Phone namespace lets you load a JPEG file from a Stream but with a maximum Width and Height. This is useful if you know that a particular JPEG might be much larger than what you need to display on the phone. The method returns a WritableBitmap.

  • An Extensions class in the System.Windows.Media.Imaging namespace has two extension methods to WriteableBitmap: LoadJpeg (which doesn’t provide additional functionality over the SetSource method defined by BitmapSource) and SaveJpeg, which lets you alter the width and height of the image and specify a compression quality.

  • The SavePicture method of the XNA MediaLibrary class lets you save a bitmap to the phone’s picture library from a Stream or a byte array in JPEG format. You’ll probably use this in conjunction with the SaveJpeg extension method with a MemoryStream intermediary.

Other -----------------
- Vector Graphics : The Path Markup Syntax
- Vector Graphics : Bézier Curves
- Vector Graphics : The Versatile PathGeometry
- Vector Graphics : Grouping Geometries
- Vector Graphics : Geometries and Transforms
- Vector Graphics : The Path Element
- Vector Graphics : Dynamic Polygons
- Vector Graphics : The Stretch Property
- Vector Graphics : Polygon and Fill
- Vector Graphics : Caps, Joins, and Dashes
- Vector Graphics : Polylines and Custom Curves
- Vector Graphics : Overlapping and ZIndex
- Vector Graphics : Canvas and Grid
- Vector Graphics : The Shapes Library
- Data Bindings : TextBox Binding Updates
- Data Bindings : Give and Take
- Data Bindings : Converters with Properties
- Data Bindings : Simple Decision Making
- Data Bindings : Setting the DataContext
- Data Bindings : A Simple Binding Server
 
 
Most view of day
- Integrating SharePoint 2013 with the Office Applications (part 8) - Microsoft InfoPath -Deploying a Form Via Central Administration, Rendering a Form Using the InfoPath Form Web Part
- Zero Touch Installations : Creating and Capturing a Reference Image (part 3) - Advertise the Reference Image Task Sequence, Run the Reference Image Task Sequence
- Microsoft Project 2010 : Setting Up a Project Budget - Setting the Project Fiscal Year
- Maintaining Desktop Health : Using Performance Information And Tools
- Windows Live Services That Make Windows 7 Better (part 5) - Windows Live Essentials
- Client Access to Exchange Server 2007 : Getting the Most Out of the Microsoft Outlook Client - What's New in Outlook 2007
- Microsoft Dynamics CRM 2011 : Using Advanced Find (part 5) - Using Edit Multiple Records and Assign Multiple Records from Advanced Find
- SQL Server 2008 R2 : Managing Workloads with the Resource Governor - Monitoring Resource Usage
- Windows Phone 7 : The Silverlight Controls (part 7) - Layout Controls - Grid Controls
- SQL Server 2012 : Running SQL Server in A Virtual Environment - WHY VIRTUALIZE A SERVER?
Top 10
- Windows Phone 8 : Configuring Mailbox Settings (part 5) - Configuring Automatic Replies
- Windows Phone 8 : Configuring Mailbox Settings (part 4) - Lightening the Display,Changing the Mailbox Sync Settings
- Windows Phone 8 : Configuring Mailbox Settings (part 3) - Message Signatures, Blind CCing Yourself
- Windows Phone 8 : Configuring Mailbox Settings (part 2) - Unlinking Mailboxes, Conversation View
- Windows Phone 8 : Configuring Mailbox Settings (part 1) - Linking Mailboxes
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 6) - Tracking installed roles, role services, and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 5) - Installing components at the prompt
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 4) - Managing server binaries
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 3) - Adding server roles and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 2) - Installing components with Server Manager - Viewing configured roles and role services
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro