Reputation: 3134
I need to create a drawing with a circle and text embeded to it .This drawing is outputted as Image file (Jpeg/Jpg/svg/Png) using c# GDI+ .
Since i dont want to display the UI directly on a form ,how do i get the graphic's object to start drawing.
Thanks in advance.
Upvotes: 1
Views: 659
Reputation: 136154
You create a Bitmap, and get the graphics object from it to draw on:
Bitmap myBitmap = new Bitmap(@"C:\MyImg.bmp");
Graphics g = Graphics.FromImage(myBitmap);
Note that the Bitmap
does not need to be created on disk, it can be created in memory too!
Upvotes: 3
Reputation: 23506
You can create a new Bitmap
passing the size for the image:
using (Bitmap myBitmap = new Bitmap(100, 100)) {
using (Graphics g = Graphics.FromImage(myBitmap)) {
// do your drawing here
}
myBitmap.Save(@"C:\path\for\image.bmp");
}
Optionally you can set the ImageFormat
for the image when saving
myBitmap.Save(@"C:\path\for\image.png", ImageFormat.Png);
Upvotes: 4