2014年11月14日 星期五

【在 GDI+ 中發生泛型錯誤】

2014/11/12   VB.NET   DataMatrix_VBCode\Server


GDI 的全名是 Graphics Device Interface 的縮寫,是在 Windows 平台內十分重要的核心元件,負責處理許多跟影像物件有關的工作

發生 GDI+ 的錯誤就一定不是 .NET 程式語法的錯誤,而且錯誤訊息是直接從 GDI+ 傳來的
http://blog.miniasp.com/post/2009/05/30/A-generic-error-occurred-in-GDI-plus.aspx

這次程式因為影像存檔放在執行緒中執行,誘發影像stream已使用中的狀況,故將此存取的動作先寫入 MemoryStream 再進行存檔的動作

Dim MyImg As Image
Dim MyStream As System.IO.MemoryStream = New System.IO.MemoryStream
Dim SFD As SaveFileDialog= New SaveFileDialog

SFD.FileName = "R:\GDI.bmp"
MyImg.Save(MyStream, System.Drawing.Imaging.ImageFormat.Bmp)

Dim MyFs As System.IO.FileStream = System.IO.File.OpenWrite(SFD.FileName)
Dim NewBitMapData As Byte() = MyStream.ToArray

MyFs.Write(NewBitMapData, 0, NewBitMapData.Length)
MyFs.Close()

沒有留言:

張貼留言