Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>in .Net 3.5/4 you can also use WPF/<a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.aspx" rel="noreferrer">Media.Imaging</a> as an alternative to GDI+</p> <p>First create a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingvisual.aspx" rel="noreferrer">DrawingVisual</a> and a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.drawingcontext.aspx" rel="noreferrer">DrawingContext</a>:</p> <pre><code>DrawingVisual visual = new DrawingVisual(); DrawingContext dc = visual.RenderOpen(); </code></pre> <p>Then draw stuff on it:</p> <pre><code>dc.DrawRectangle(...); dc.DrawText(...); etc... </code></pre> <p>Make sure you close it:</p> <pre><code> dc.Close(); </code></pre> <p>The great thing about WPF is everything in the GUI is actually a visual too, so if you prefer you don't have to use the code above to draw programatically, you can actually build up your visual in xaml on a window and then just render that straight to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx" rel="noreferrer">RenderTargetBitmap</a>.</p> <p>Once you have built your visual you can render it to a file using an encoder (.Net has encoders for <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.jpegbitmapencoder.aspx" rel="noreferrer">Jpeg</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapencoder.aspx" rel="noreferrer">Png</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bmpbitmapencoder.aspx" rel="noreferrer">Bmp</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.gifbitmapencoder.aspx" rel="noreferrer">Gif</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.tiffbitmapencoder.aspx" rel="noreferrer">Tiff</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.wmpbitmapencoder.aspx" rel="noreferrer">Wmp</a>). </p> <pre><code>// Create a render target to render your visual onto. The '96' values are the dpi's, you can set this as required. RenderTargetBitmap frame = new RenderTargetBitmap((int)visual.ContentBounds.Width, (int)visual.ContentBounds.Height, 96, 96, PixelFormats.Pbgra32); frame.Render(visual); // Now encode the rendered target into Jpeg and output to a file. JpegBitmapEncoder jpeg = new JpegBitmapEncoder(); jpeg.Frames.Add(BitmapFrame.Create(frame)); using (Stream fs = File.Create(@"c:\filename.jpg")) { jpeg.Save(fs); } </code></pre> <p>There are some good MS Tutorials on <a href="http://msdn.microsoft.com/en-us/library/ms751619.aspx" rel="noreferrer">Drawing Objects</a> and <a href="http://msdn.microsoft.com/en-us/library/ms748373.aspx" rel="noreferrer">WPF Graphics Rendering</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload