2011-03-04 86 views

回答

5

是這樣的?

Bitmap bmp = new Bitmap(300, 300); 
Graphics g = Graphics.FromImage(bmp); 

g.Clear(Color.Transparent); 
g.FillRectangle(Brushes.Red, 100, 100, 100, 100); 

g.Flush(); 
bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png); 

(從here

你不得不玩的過程中的圖像的內容,但顯卡的命名空間可能有你最需要什麼。

+1

出於某種原因,我從來沒有注意到Clear方法。我一直在整個表面手動使用FillRectangle,所以感謝kprobst。 :) – Jonathan 2012-06-28 08:07:50

5

您可以使用.NET框架中的Bitmap和其他圖形相關類來做到這一點。

 Bitmap bmpImage = new Bitmap(width, height); 
     Graphics gr = Graphics.FromImage(bmpImage); 
     //Draw using gr here 

     //stream to the client 
     Response.ContentType = "image/png"; 

     //write to memory stream first, png can only be written to seekable stream 
     using(MemoryStream memStream = new MemoryStream()) 
     { 
      bmpImage.Save(memStream, ImageFormat.Png); 
      memStream.WriteTo(Response.OutputStream); 
     } 
     bmpImage.Dispose(); 
+0

你*必須*圍繞所有System.Drawing對象(圖形,位圖)包裝using子句。具有諷刺意味的是,MemoryStream甚至沒有做任何處置時間。 – 2012-04-21 15:34:17

相關問題