0

ex winform:

Graphics g = Graphics.FromImage(newimg);
String str = "hello world";
Font font = new Font("Arial", 30);
SolidBrush sbrush = new SolidBrush(Color.Black);
g.DrawString(str, font, sbrush, new PointF(100, 120));

In the WPF on how the InteropBitmap to do the same thing?

Leo
  • 37,640
  • 8
  • 75
  • 100
leeolevis
  • 13
  • 4
  • Does the example work for you when running it in Winforms..? check this working example - http://stackoverflow.com/questions/6311545/c-sharp-write-text-on-bitmap – MethodMan Jan 08 '13 at 07:04

1 Answers1

0

The graphics object in Wpf is different than Winforms since Wpf uses Vector Graphics. In Wpf you will be using a DrawingVisual, DrawingContext, FormattedText and a BitmapImage, the DrawingContext is equivalent to the Graphics object in Winforms. This is a quick example to show what I mean.

public MainWindow()
{
    InitializeComponent();

    Grid myGrid = new Grid();
    BitmapImage bmp = new BitmapImage(new Uri(@"C:\temp\test.jpg")); //Use the path to your Image 
    DrawingVisual dv = new DrawingVisual();
    DrawingContext dc = dv.RenderOpen();
    dc.DrawImage(bmp, new Rect(100, 100, 300, 300));

    dc.DrawText(new FormattedText("Hello World",
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface("Arial"),
                30, System.Windows.Media.Brushes.Black),
                new System.Windows.Point(100, 120));

    dc.Close();

    myGrid.Background = new VisualBrush(dv); 
    this.Content = myGrid;
}
Mark Hall
  • 53,938
  • 9
  • 94
  • 111