Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>// Create the bitmap we'll render to RenderTargetBitmap bmp = new RenderTargetBitmap(100, 100, // Size 96, 96, // DPI PixelFormats.Pbgra32); // Create a list of random circle geometries List&lt;Geometry&gt; geoList = new List&lt;Geometry&gt;(); Random rand = new Random(); for (int i=0; i&lt;10; i++) { double radius = rand.Next(5, 10); Point center = new Point(rand.Next(25, 75), rand.Next(25,75)); geoList.Add(new EllipseGeometry(center, radius, radius)); } // The light-weight visual element that will draw the geometries DrawingVisual viz = new DrawingVisual(); using (DrawingContext dc = viz.RenderOpen()) { // The DC lets us draw to the DrawingVisual directly foreach (var g in geoList) dc.DrawGeometry(Brushes.Red, null, g); } // the DC is closed as it falls out of the using statement // draw the visual on the bitmap bmp.Render(viz); // instantiate an encoder to save the file PngBitmapEncoder pngEncoder = new PngBitmapEncoder(); // add this bitmap to the encoders set of frames pngEncoder.Frames.Add(BitmapFrame.Create(bmp)); // save the bitmap as an .png file using (FileStream file = new FileStream("Spots.png", FileMode.Create)) pngEncoder.Save(file); </code></pre> <p>Based on your comments to the section above, it looks like you're trying to create a table of glyphs for a font and save it out to an image file. Here's how you accomplish this:</p> <pre><code>// I'm generating the glyphs differently for testing. // I tested with fontName="Arial" Typeface face = new Typeface(fontName); GlyphTypeface font; if (!face.TryGetGlyphTypeface(out font)) return; // bail if something goes wrong int ColumnCount = 10; int MaxDrawCount = 30; // use int.MaxValue to draw them all double fontSize = 50d; // the height of each cell has to include over/underhanging glyphs Size cellSize = new Size(fontSize, fontSize * font.Height); var Glyphs = from glyphIndex in font.CharacterToGlyphMap.Values select font.GetGlyphOutline(glyphIndex, fontSize, 1d); // now create the visual we'll draw them to DrawingVisual viz = new DrawingVisual(); int drawCount = -1; using (DrawingContext dc = viz.RenderOpen()) { foreach (var g in Glyphs) { drawCount++; if (drawCount &gt;= MaxDrawCount) break; // don't draw more than you want if (g.IsEmpty()) continue; // don't draw the blank ones // center horizontally in the cell double xOffset = (drawCount % ColumnCount) * cellSize.Width + cellSize.Width / 2d - g.Bounds.Width / 2d; // place the character on the baseline of the cell double yOffset = (drawCount / ColumnCount) * cellSize.Height + fontSize * font.Baseline; dc.PushTransform(new TranslateTransform(xOffset, yOffset)); dc.DrawGeometry(Brushes.Red, null, g); dc.Pop(); // get rid of the transform } } int RowCount = drawCount / ColumnCount; if (drawCount % ColumnCount != 0) RowCount++; // to include partial rows int bitWidth = (int)Math.Ceiling(cellSize.Width * ColumnCount); int bitHeight = (int)Math.Ceiling(cellSize.Height * RowCount); RenderTargetBitmap bmp = new RenderTargetBitmap( bitWidth, bitHeight, 96, 96, PixelFormats.Pbgra32); bmp.Render(viz); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bmp)); using (FileStream file = new FileStream("FontTable.png", FileMode.Create)) encoder.Save(file); </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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