Link to home
Start Free TrialLog in
Avatar of jinksk1957
jinksk1957Flag for United States of America

asked on

In C#.NET, how can I anti-alias an image object.

In C#.NET, how can I anti-alias an image object and copy it to the clipboard so that the target app (Word) recognizes the anti-aliasing of the lines?

I have a diagraming application that allows a user to create a polar grid diagram use to plot wind envelopes. I am using the Syncfusion Diagraming control for Windows Forms that allows you to export the diagram's content to an image object. However, there seems to be no way to preserve the anti-aliasing of the original diagram when the image object is sent through the Clipboard to Microsoft Word.

Am I doing something wrong or is this impossible? I have seen other software do this: Visio to Word, et.al.
Avatar of jimbobmcgee
jimbobmcgee
Flag of United Kingdom of Great Britain and Northern Ireland image

The only way I would think you could do this is if you can stream the image in a vector-based format.  The only one I think .NET supports out of the box is WMF.  Something like:

    bmp.Save(myStream, ImageFormat.Wmf);

Otherwise, if you can access the underlying Graphics object used to draw the chart to the image, you may be able to use:

   gfx.SmoothingMode = SmoothingMode.AntiAlias;

Otherwise, you just have to create the image in as large a resolution as you dare and let the target app treat it as it chooses.  If you try to display it in an area smaller than the image data, Word should resize it nicely enough.  If you try to display it in an area larger than the image data, it will start to look blocky.

J.
Avatar of jinksk1957

ASKER

jimbobmcgee;

    Your answer looks promising; however, I can't get directly at the underlying Graphics object of the Diagram control. They do provide two export (to memory) methods:

    ExportDiagramAsImage(bool respectBounds)
    ExportDiagramAsGraphics(Graphics gfx)

I can easily find the Clipboard.SetImage(Image image) method to copy as an image; however, there is no equivalent Clipboard.SetGraphics(Graphics gfx) method. Do I use Clipboard.SetDataObject() instead?
ASKER CERTIFIED SOLUTION
Avatar of jimbobmcgee
jimbobmcgee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Otherwise, you are just going to have to use a significantly bigger width/height combo and let Word resize it down.  It will always look better sizing a large image down than a small image up.

J.
Thanks jimbob! That works great. Now I've just got to figure out how to just get what I want from their Diagram control to copy and not the whole page. Thanks again for the help