Bad quality (again)

May 11 2009 2:45 PM
Greetings everyone. I try to print my own control (combination of labels and textfields). I use DrawToBitmap() method but it gives bad quality in result.

I tried to override it (with better quality as i thought):

private void DrawToBitmapEx(Bitmap bitmap, Rectangle targetBounds)
        {
            int width = Math.Min(this.Width, targetBounds.Width);
            int height = Math.Min(this.Height, targetBounds.Height);
            Bitmap image = new Bitmap(width, height, bitmap.PixelFormat);
           
            using (Graphics graphics = Graphics.FromImage(image))
            {
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                IntPtr hdc = graphics.GetHdc();
                UnsafeNativeMethods.SendMessage( (IntPtr)(new HandleRef(this, this.Handle)), 0x317, hdc, (IntPtr)30);

                using (Graphics graphics2 = Graphics.FromImage(bitmap))
                {
                    graphics2.SmoothingMode = SmoothingMode.HighQuality;
                    graphics2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    graphics2.CompositingQuality = CompositingQuality.HighQuality;
                    graphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    IntPtr handle = graphics2.GetHdc();
                    SafeNativeMethods.BitBlt( (IntPtr)(new HandleRef(graphics2, handle)), targetBounds.X, targetBounds.Y, width, height, (IntPtr)(new HandleRef(graphics, hdc)), 0, 0, 0xcc0020);

                    graphics2.ReleaseHdcInternal(handle);
                }
                graphics.ReleaseHdcInternal(hdc);
            }                        
        }


but nothing changed. I see pixels on paper. Is there any way to solve this problem? Thnx.

Answers (1)