I am doing a console application in c#. In this app, I have to create a bitmap of png type and it has to to be stored in some defined path (say C: or D: drive).
In a windows application I have the below code to create a bitmap and it will be shown in a picture box.
void CreateBitmap()
{
System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10);
for( int x = 0; x < flag.Height; ++x )
for( int y = 0; y < flag.Width; ++y )
flag.SetPixel(x, y, Color.White);
for( int x = 0; x < flag.Height; ++x )
flag.SetPixel(x, x, Color.Red);
pictureBox1.Image = flag;
}
How can I create and store this in a specified path using a console application?
I have changed my code as below but still error exists:
static void CreatePng(string[] binvalues)
{
String aName = System.Reflection.Assembly.GetExecutingAssembly().Location;
String aPath = System.IO.Path.GetDirectoryName(aName);
string[] ExecDirectories = System.IO.Directory.GetDirectories(aPath);
System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10);
for (int x = 0; x < flag.Height; ++x)
for (int y = 0; y < flag.Width; ++y)
flag.SetPixel(x, y, Color.White);
for (int x = 0; x < flag.Height; ++x)
flag.SetPixel(x, x, Color.Red);
flag.Save(aPath, System.Drawing.Imaging.ImageFormat.Png);
}
It is showing run-time error in last line where flag.save seems something wrong?