Dela via


Programming Graphics in the .NET Compact Framework

You can create robust and visually stimulating applications by using the .NET Compact Framework. You can also use platform invoke to obtain special effects from native code. In the .NET Compact Framework version 2.0 and later versions, you can program Direct3D applications. For more information about DirectX and Direct3D in the .NET Compact Framework, see Windows Mobile DirectX and Direct3D.

Consider the following points when programming graphic objects in the .NET Compact Framework:

  • The .NET Compact Framework does not support GDI+. Several Graphics class methods that perform complex drawing, filling, and transformation operations are not supported. Paths, arcs, 2-D, and 3-D are not supported.

    However, the .NET Compact Framework does support core drawing primitives and their corresponding fill methods: ellipse, line, image, polygon, rectangle, string, and region.

  • You can write code for high-resolution applications. For more information about high resolution, see How to: Handle Orientation and Resolution Changes.

  • Only color-keyed transparency is supported. Alpha blending, the pixel-by-pixel blending of source and background color data, is not supported. Accordingly, the colorLow and colorHigh parameters of the SetColorKey method must be the same color.

  • The .NET Compact Framework and the full .NET Framework evaluate comparisons with known colors differently. In the .NET Compact Framework, when you compare a known color, such as Aquamarine, with a color that has the same RGB values as Aquamarine, the result will be the same. The full .NET Framework evaluates these colors as different because known colors contain identifying information beyond the RGB values.

  • The .NET Compact Framework does not support the constructor for the Font class that uses an existing Font object.

  • You can use the CreateGraphics method only on a Form or Control object.

  • If an image fails to load, ensure that imgdecmp.dll is in the Windows directory in the device.

  • The Clone and FromHandle methods of an Icon are operational on devices that are running Windows Mobile version 5.0. The .NET Compact Framework supports high-resolution icons, but not high-color icons.

  • The .NET Compact Framework does not support gradient brushes. However, you can interoperate with native functions to achieve gradient displays. For an example, see How to: Display a Gradient Fill.

Improving Draw Speeds

The following coding practices can improve drawing performance when using Graphics objects:

  • Create only one Graphics object, or use the object from PaintEventArgs in the OnPaint method.

  • Draw to an off-screen bitmap, and then draw the bitmap to the display all at once. For a code example, see How to: Draw Images Off-Screen.

  • Redraw only the parts of the image that have changed.

  • Draw the same destination and source sizes; avoid stretching whenever possible.

  • Minimize the number of draws that occur by keeping track of the items that need to be redrawn. For example, when dragging a cursor across an image, it is not necessary to redraw the entire image. Instead, redraw only the section of the image that the previous cursor position overwrote.

See Also

Other Resources

Mobile Direct3D Programming in the .NET Compact Framework

Interoperability in the .NET Compact Framework

Graphics and Drawing in the .NET Compact Framework