Home > DeveloperSection > Forums > In WPF how to give the InteropBitmap drawing font
Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    September-23-2013 4:51 AM


 1 Reply(s)
 1288  View(s)
Rate this:

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?

Sumit Kesarwani

Total Post:378

Posted on    September-23-2013 6:57 AM

Hi Manoj,

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()



    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",



                new Typeface("Arial"),

                30, System.Windows.Media.Brushes.Black),

                new System.Windows.Point(100, 120));


    myGrid.Background = new VisualBrush(dv);

    this.Content = myGrid;


Don't want to miss updates? Please click the below button!

Follow MindStick