.NET Forum / .NET Framework / .NET SDK / November 2005
Graphics.DrawImage(metafile) - no antialiasing
|
|
Thread rating:  |
David Thielen - 13 Nov 2005 23:07 GMT Hello;
I am using the following code to render a metafile:
Metafile mf = new Metafile("../../text box line.emf"); System.Drawing.Bitmap img = new System.Drawing.Bitmap(mf.get_Width(), mf.get_Height()); img.SetResolution(72, 72); Graphics g = Graphics.FromImage(img); SolidBrush sb = new SolidBrush(Color.get_White()); g.FillRectangle(sb,0,0,301,149); g.DrawImage(mf, 0, 0, 301, 149);
The rendered image does no anti-aliasing on the text or daiganol line. So they look bad. How can I get anti-aliasing?
 Signature thanks - dave
Wei-Dong XU [MSFT] - 14 Nov 2005 06:19 GMT Hi,
Currently I am finding one support professional for you on this issue. If any update, we will reply at the first time.
Best Regards, Wei-Dong XU Microsoft Product Support Services This posting is provided "AS IS" with no warranties, and confers no rights. It is my pleasure to be of assistance.
"Peter Huang" [MSFT] - 15 Nov 2005 10:18 GMT Hi
You may take a look at the link below. Antialiasing with Text http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm l/_gdiplus_antialiasing_with_text_usecsharp.asp Antialiasing with Lines and Curves http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm l/_gdiplus_antialiasing_with_lines_and_curves_about.asp
I think you need to set the Antialiasing options when you create the emf file with drawstring or DrawLine...
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 17 Nov 2005 22:51 GMT I tried that - didn't work: Metafile mf = new Metafile("../../text box line.wmf"); System.Drawing.Bitmap img = new System.Drawing.Bitmap(mf.get_Width(), mf.get_Height(), PixelFormat.Format32bppArgb); img.SetResolution(72, 72);
Graphics g = Graphics.FromImage(img); g.set_TextRenderingHint(System.Drawing.Text.TextRenderingHint.AntiAlias); g.set_SmoothingMode(System.Drawing.Drawing2D.SmoothingMode.AntiAlias) g.set_CompositingQuality(System.Drawing.Drawing2D.CompositingQuality.HighQuality); // tried with and without this SolidBrush sb = new SolidBrush(Color.get_White()); g.FillRectangle(sb,0,0,img.get_Width(),mf.get_Height());
g.DrawImage(mf, 0, 0, img.get_Width(), mf.get_Height());
img.Save("../../output.png", ImageFormat.get_Png());
What else do I need to do?
 Signature thanks - dave
> Hi > [quoted text clipped - 16 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. "Peter Huang" [MSFT] - 18 Nov 2005 03:12 GMT Hi
I think you may try set the AntiAlias feature when you create the wmf. e.g. When you DrawLine onto the wmf, you need to enable the AntiAlias.
Also here is a reference. http://dotnet247.com/247reference/msgs/28/144605.aspx
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 18 Nov 2005 04:05 GMT Hello;
The metafile stores it as a text string/font/size. But there is nothing in the metafile record about smoothing.
The link you gave me says that when a metafile plays, it does not do smoothing. But I find it hard to believe that this is the case - that would be a really poor implementation (IMHO) as it eliminates the whole benefit of a vector based file.
Can you please check with the development group about this?
 Signature thanks - dave
> Hi > [quoted text clipped - 11 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. "Peter Huang" [MSFT] - 19 Nov 2005 02:30 GMT Hi
When we draw a metafile, it is play the records, because in the metafile what we stored is the information about the vector information about circle but not he pixel information. So as John in the google link before, you'd need to enumerate the records and convert to corresponding GDI+ calls in order to use the smoothing mode. Also it seems the WMF will be many GDI call, for detailed information I think the gdi newsgroup is a better choice. microsoft.public.win32.programmer.gdi
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 19 Nov 2005 05:01 GMT Hello;
I find it hard to believe that the .net metafile player does not have anti-aliasing as an option - that would be a really poor implementation (IMHO) as it eliminates the whole benefit of a vector based file.
Can you please check with the development group about this?
 Signature thanks - dave
> Hi > [quoted text clipped - 14 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. "Peter Huang" [MSFT] - 21 Nov 2005 07:36 GMT Hi
As John(who is a experienced senior engineer) said, we need to get the record and play the record again. We can consider the metafile and a collection of drawing steps. e.g. DrawString,DrawArc,DrawLine......., when we draw the metafile, it is playing the record to get the result metafile image. So if we did not tell in the metafile that we want AntiAlias, so it did not use AntiAlias. So we need to divide the metafile into the detailed Draw command(maybe more lower GDI command) to redraw the metafile one step by one steps with the AntiAlias.
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 21 Nov 2005 13:36 GMT Hi;
I understand that. And I am sure drawImage() does that. But I am guessing there is a way to tell drawImage() to turn on anti-aliasing when it makes the draw calls.
We presently are 100% managed code and I am trying to kepp it that way. Making direct GDI calls means we are no longer 100% managed code. (And isn't .net 2.0 supposed to make direct calls unnecessary?)
Can you please ask the .NET development group if there is a way to do this via drawImage? I can't believe they wouldn't make this an option.
 Signature thanks - dave
> Hi > [quoted text clipped - 15 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. "Peter Huang" [MSFT] - 22 Nov 2005 06:51 GMT Hi
Based on my research, all the Overload List of DrawImage did not have an options to enable the antialiasing. Also I will try to forward your concern to see if there is any other appraoch.
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 22 Nov 2005 13:41 GMT thank you - dave
> Hi > [quoted text clipped - 10 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights. "Peter Huang" [MSFT] - 29 Nov 2005 02:13 GMT Hi
I confirmed with Dev team, we do need to enumerate all the records again and draw the records again with antialiasing. We can use the EnumerateMetafile to get the records. I would be somewhat like below. ......... 00000008 0.00067020 [4864] WmfSelectObject 00000009 0.00073138 [4864] WmfCreateBrushIndirect 00000010 0.00082301 [4864] WmfSelectObject 00000011 0.00161389 [4864] WmfSetPolyFillMode 00000012 0.00172592 [4864] WmfPolygon 00000013 0.00181755 [4864] WmfCreateBrushIndirect 00000014 0.00188907 [4864] WmfSelectObject 00000015 0.00195164 [4864] WmfSelectObject 00000016 0.00201310 [4864] WmfSelectObject 00000017 0.00207484 [4864] WmfSelectObject 00000018 0.00228381 [4864] WmfSetPolyFillMode 00000019 0.00234527 [4864] WmfPolygon 00000020 0.00240645 [4864] WmfSelectObject 00000021 0.00241986 [4864] WmfSelectObject 00000022 0.00248970 [4864] WmfSelectObject 00000023 0.00259837 [4864] WmfSelectObject 00000024 0.00284142 [4864] WmfSetPolyFillMode 00000025 0.00290456 [4864] WmfPolygon 00000026 0.00296574 [4864] WmfSelectObject 00000027 0.00303279 [4864] WmfSelectObject 00000028 0.00309425 [4864] WmfSelectObject 00000029 0.00315599 [4864] WmfSelectObject 00000030 0.00323617 [4864] WmfSetPolyFillMode 00000031 0.00329791 [4864] WmfPolygon ..................
You'd need to map GDI calls to GDI+ (System.Drawing) calls. For example, for a Polygon record, you would call DrawPolygon(). This is obviously non-trivial as you'd need to keep track of the brush attributes and create an appropriate Brush object, same for Pen, etc..
Best regards,
Peter Huang Microsoft Online Partner Support
 Signature Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen - 29 Nov 2005 04:47 GMT Hi;
Amazing that they didn't do this. Thanks for checking.
 Signature thanks - dave
> Hi > [quoted text clipped - 41 lines] > Get Secure! - www.microsoft.com/security > This posting is provided "AS IS" with no warranties, and confers no rights.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|