2013-12-18 43 views
0

我需要在运行时创建一个空白图像。我试着创建一个,并创建一个,将其保存到磁盘然后访问它。我正在序列化它们的一个数组,所以我不能跳过一个。我也看过一个Forge,一些整洁的纹理方法,但我不熟悉他们的文档。我试图快速实现一些东西,我发现这里..运行时创建映像 - aForge?

Bitmap bmp = new Bitmap(255, 255); 
    using (Graphics gfx = Graphics.FromImage(bmp)) 
    using (SolidBrush brush = new SolidBrush(Color.FromArgb(0, 0, 0))) 
    { 
     gfx.FillRectangle(brush, 0, 0, 255, 255); 
    } 

using (Bitmap bitmap = new Bitmap(255, 255)) 
    { 
     using (Graphics graphics = Graphics.FromImage(bitmap)) 
     { 
      SolidBrush brush = new SolidBrush(Color.FromArgb(0, 0, 0)); 
     } 
     bitmap.Save(dirPath + "\\" + "_Error_Image.png"); 
    } 

既不工作了。有没有人有一个简单的方法来完成这个?

+0

你是什么意思“既没有解决”?发生了什么?你期望会发生什么? –

+0

你想要一个“空”的图像,或者是一个充满黑色的图像--Color.FromArgb(0,0,0) - 是黑色的,你是否缺少alpha或有效,你需要什么? – terrybozzio

+0

您没有在代码中绘制任何位图对象库。 – Jade

回答

0

它可能是你想要的吗?

Bitmap bitmap = new Bitmap(255, 255)) 

bitmap.Save(dirPath + "\\" + "_Error_Image.png"); 

如果空你的意思是什么也没有,这将做到这一点,如果你想以供将来参考Color.FromArgb(0, 0, 0, 0)你的颜色设置为透明 - 第一个参数是阿尔法其中0 =透明,255 =完全不透明。