Basics: Bitmap and pixel bits

Source: Internet
Author: User
Tags constructor transparent image

The Windows®presentation Foundation (WPF) retention-mode graphics system has brought dramatic changes to Windows graphics programming. The program no longer needs to recreate its visual appearance on the screen as required by the system. The composite system retains all the graphic numbers and arranges them into the entire visual appearance.

Retaining pattern graphics does simplify workflow, but for Windows programmers, simplicity is not the primary concern. In fact, it is the combination of the reserved pattern graphics system and the notification mechanism (dependency property) that makes WPF flexibility and functionality manifest. Drawing objects, such as paths and brushes, appear to still "exist" in the composite system and continue to respond to property changes and graphic transformations, allowing data binding and animation effects on these objects.

Recently, I found that a WPF bitmap has a similar dynamic nature: The rendered bitmap still responds to changes-not only in response to graphic transformations (well known), but also in response to changes in the actual pixel bits in the bitmap.

The two bitmap classes that show this dynamic response are RenderTargetBitmap and WriteableBitmap, which are members of 9 classes derived from BitmapSource; BitmapSource is an abstract class and is a WPF The base of all bitmaps supported in. A program can display one of these bitmap objects with an image element, make it into a tile brush using the ImageBrush class, or use the ImageDrawing class as part of a large drawing (which may be mixed with vector graphics), but either way, Will not be ignored when the bitmap is rendered. Instead, the bitmap remains in the visual composite system and continues to respond to application changes.

Using RenderTargetBitmap

RenderTargetBitmap is a bitmap that can be effectively drawn by transferring objects of Visual type to its surface. The only way to create a new object of the RenderTargetBitmap type is to use a constructor, and you need to provide that constructor with the pixel dimensions of the bitmap, the horizontal and vertical resolution in dots per inch, and the PixelFormat type of object.

Later, I'll detail the PIXELFORMAT structure and related static pixelformats classes. To create an object of type RenderTargetBitmap, you must use Pixelformats.default or Pixelformats.pbgra32 as the last parameter of the RenderTargetBitmap constructor. Regardless of which one you use, you can create a transparent bitmap of 32 bits per pixel.

Initially, the RenderTargetBitmap object is completely transparent. You can then use objects of visual type, including classes derived from visual, such as FrameworkElement and control, to invoke the Render method to draw on this bitmap. By calling clear, you can restore a fully transparent image. If the bitmap is currently displayed, the above call is immediately reflected in the displayed bitmap.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.