System.Windows.Controls.Image anImage = new System.Windows.Controls.Image();
var gt = new GlyphTypeface(new Uri(@"file:///C:\WINDOWS\Fonts\MSPgothic.ttf")); char ch = 'あ'; ushort glyphIndex; //charから指定したフォントのGlyphIndexを取得 gt.CharacterToGlyphMap.TryGetValue((int)ch, out glyphIndex); Geometry GlyLine = gt.GetGlyphOutline(glyphIndex, 50, 2);
var gd = new GeometryDrawing(); gd.Geometry = GlyLine; gd.Brush = new LinearGradientBrush( Colors.Blue, Color.FromRgb(200, 200, 205), new Point(0, 0),//グラディエーション開始 new Point(1, 1));//グラディエーション終了 gd.Pen = new Pen(Brushes.White, 1);
DrawingImage geometryImage = new DrawingImage(gd);
var bmp = new System.Windows.Media.Imaging.RenderTargetBitmap((int)anImage.ActualWidth + 10, (int)anImage.ActualHeight + 10, 100, 100, PixelFormats.Pbgra32); bmp.Render((Visual)anImage);//既に表示されているものしかRender出来ないらしい… //pngに保存 var bmpFrame = System.Windows.Media.Imaging.BitmapFrame.Create(bmp); var stream = new System.IO.FileStream(@"test.png", System.IO.FileMode.Create); var enc = new System.Windows.Media.Imaging.PngBitmapEncoder(); enc.Frames.Add(bmpFrame); enc.Save(stream); stream.Close();