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



The information in this article 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 "write only." 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 "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Microsoft Visual Studio. NET.
  2. On the File menu, click New, and then click Project.

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

    By default, the Form1.cs file appears.

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

    The Add Reference dialog box appears.
  7. 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:
  8. Click OK to add the reference to the project that you create.
  9. Right-click Form1, and then click View Code.
  10. 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());
    	}
    }
    
  11. On the Build menu, click Build Solution.
  12. On the Debug menu, click Start.
  13. Try to write something in the first frame by using your mouse.

    You may notice the problem that is mentioned in the "Symptoms" section.

REFERENCES

For additional information about about Tablet PC pen and ink, visit the following Microsoft Developer Network (MSDN) Web site:For additional information about printing ink, visit the following MSDN Web site: For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

311221 Interoperability between GDI and GDI+


Modification Type:MajorLast Reviewed:7/8/2004
Keywords:kbgraphic kbGDIPlus kbView kbtshoot kbbug KB867631 kbAudDeveloper