Microsoft KB Archive/867631

= BUG: A bitmap does not render the Antialiased property, the Transparency property, and the Color property in the .NET Framework =

Article ID: 867631

Article Last Modified on 4/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-





SYMPTOMS
The Antialiased property, the Transparency property, and the Color property are not reflected in a bitmap when you try to draw an image by using the Render.Draw method. The image appears only as a black color in the bitmap field. However, the Transparency property and the Color property are reflected when rendered directly to the Graphics object of a control.



CAUSE
When you try to render the Antialiased property, the Transparency property, and the Color property to a bitmap, you use Graphics Device Interface (GDI) on a GDI+ graphics object to do this. The Graphics::GetHDC method is called for the Graphics object that is backed by a bitmap instead of by a screen.

When the Graphics::GetHDC method is called, a memory HDC internal method is created, and then a new HBITMAP handle object is created and is put in the memory HDC internal method. This new memory bitmap is not initialized with the original image of the bitmap. This new memory bitmap is initialized with a sentinel pattern that enables GDI+ graphics object to track changes to the new memory bitmap. Any changes that are made to the new memory bitmap by using the GDI code become noticeable in the changes to the sentinel pattern. When the Graphics::ReleaseHDC method is called, those changes are copied back to the original bitmap. Because the new memory bitmap is not initialized with the image of the original bitmap, an HDC internal method that is obtained in this way is considered &quot;write only.&quot; Therefore the HDC internal method is not suitable for use with Raster Operations (ROPs) that require the ability to read the target. For example, the HDC internal method is not suitable for use with the R2_XOR Raster Operation.

Also, there is a performance cost to this approach. The GDI+ graphics object has to copy the changes back to the original bitmap.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
 Start Microsoft Visual Studio. NET. On the File menu, click New, and then click Project.

The New Project dialog box appears. Under Project Types, click Visual C# Projects. Under Templates, click Windows Application. Type in the Name box, and then click OK.

By default, the Form1.cs file appears.

Note The  is a placeholder for the name of the project that you want to create. On the Project menu, click Add Reference.

The Add Reference dialog box appears.</li> On the .NET tab, click Microsoft Tablet PC API in the Component Name column, and then click Select.

The Microsoft Tablet PC API appears in the Selected Components list.

Note To add the Microsoft Tablet PC API to your program, your computer must have the Microsoft Tablet PC Platform Software Development Kit (SDK) installed.

To download the Tablet PC Platform Software Development Kit (SDK) v1.5, visit the following Web site:

http://www.microsoft.com/downloads/details.aspx?FamilyID=4b14b74a-27e4-42c4-862f-273f6302ea4f&DisplayLang=en

</li> Click OK to add the reference to the project that you create.</li> Right-click Form1, and then click View Code.</li>  Replace the existing code with the following code: using System; using System.Drawing; using System.Windows.Forms; using Microsoft.Ink; public class Form1 : System.Windows.Forms.Form {   InkPicture ip; PictureBox pb1, pb2; public Form1 {       Size = new System.Drawing.Size(300,600); ip = new InkPicture; ip.Location = new Point(0, 0); ip.Size = new Size(300, ClientRectangle.Height/3); ip.BorderStyle = BorderStyle.FixedSingle; ip.DefaultDrawingAttributes.Width = 100; ip.DefaultDrawingAttributes.AntiAliased = true; ip.DefaultDrawingAttributes.Color = Color.Red; ip.DefaultDrawingAttributes.Transparency = 200; ip.Stroke += new InkCollectorStrokeEventHandler(ip_Stroke); pb1 = new PictureBox; pb1.Location = new Point(0, ClientRectangle.Height/3); pb1.Size = new Size(300, ClientRectangle.Height/3); pb1.BorderStyle = BorderStyle.FixedSingle; pb1.Image = new Bitmap(pb1.Width, pb1.Height); pb2 = new PictureBox; pb2.Location = new Point(0, 2*ClientRectangle.Height/3); pb2.Size = new Size(300, ClientRectangle.Height/3); pb2.BorderStyle = BorderStyle.FixedSingle; Controls.AddRange(new Control[]{ip, pb1, pb2}); }   private void ip_Stroke(object s, InkCollectorStrokeEventArgs e)    { Bitmap b = new Bitmap(ip.Width, ip.Height); Graphics g1 = Graphics.FromImage(pb1.Image); Graphics g2 = pb2.CreateGraphics; ip.Renderer.Draw(g1,ip.Ink.Strokes); ip.Renderer.Draw(g2,ip.Ink.Strokes); pb1.Invalidate; ip.Invalidate; }   [STAThread] static void Main {       Application.Run(new Form1); } } </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Start.</li> Try to write something in the first frame by using your mouse.

You may notice the problem that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

<div class="references_section">