我在做c#中的控制檯應用程序。在這個應用程序中,我必須創建一個png類型的位圖,並且它必須存儲在某個定義的路徑中(比如C:或D:驅動器)。如何在c的控制檯應用程序中將位圖保存爲png#
在Windows應用程序中,我有下面的代碼來創建一個位圖,它將顯示在一個圖片框中。
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;
}
如何使用控制檯應用程序創建並將其存儲在指定路徑中?
我已經改變了我的代碼如下,但仍存在錯誤:
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);
}
它顯示在最後一行運行時錯誤的flag.save似乎出問題了嗎?
HTTP://www.whathaveyoutried。com/ – Maarten
@Marteen:你至少可以將這個鏈接打包成一個很好的評論......雖然我同意這個鏈接,它的目的,你的評論很糟糕,[並不真正有用](http:// meta .stackexchange.com /問題/ 147161 /因爲,當-是-HTTP-whathaveyoutried-COM-禁止)。 – Bobby