This article applies to MS .NET programming, simulated by .NET 3.5 SP 1 using VB.NET.
This exception happens when transferring a bitmap object over remoting and trying to load the proxy bitmap object into a picturebox.
For my case, it occurs during the invocation of System.Drawing.Graphics.DrawImage
The solution is to convert the bitmap object into bytes array (at server), transfer it to client over via remoting and then convert the bytes array into bitmap object again (at client).
hence:
1.) At the server, create a ClsImgData object and then invoke the ProcessImgTOBytesArray method.
2.) Transfers to ClsImgData object to a client via remoting.
3.) At the client, invoke the ProcessImgFROMBytesArray method of the ClsImgData object.
4.) The output file is stored in the variable img2 under ProcessImgFROMBytesArray method.
What is 'nativeImage' field ?
http://stackoverflow.com/questions/19975734/how-can-i-extract-the-image-out-of-system-drawing-bitmap-to-file-via-windbg
System.Drawing.Bitmap is a tiny managed object. It wraps a handle returned by the unmanaged GDI+ api, stored in the private nativeImage field.
This exception happens when transferring a bitmap object over remoting and trying to load the proxy bitmap object into a picturebox.
For my case, it occurs during the invocation of System.Drawing.Graphics.DrawImage
The solution is to convert the bitmap object into bytes array (at server), transfer it to client over via remoting and then convert the bytes array into bitmap object again (at client).
<Serializable()> _ Public Class ClsImgData Private img As System.Drawing.Bitmap Private imgB() As Byte Private ms As System.IO.MemoryStream Public Sub ProcessImgTOBytesArray() Try ' Assuming that it image file is a jpeg file img = New Bitmap("C:\Temp\img-data-1.jpg") ms = New System.IO.MemoryStream() img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg) imgB = ms.ToArray() Catch ex As Exception Debug.Print(ex.ToString) End Try End Sub Public Sub ProcessImgFROMBytesArray() Dim ms2 As System.IO.MemoryStream Dim img2 As System.Drawing.Bitmap Try If Not imgB Is Nothing Then ms2 = New System.IO.MemoryStream(imgB) img2 = New Bitmap(ms2) End If Catch ex As Exception Debug.Print(ex.ToString) End Try End Sub End Class
hence:
1.) At the server, create a ClsImgData object and then invoke the ProcessImgTOBytesArray method.
2.) Transfers to ClsImgData object to a client via remoting.
3.) At the client, invoke the ProcessImgFROMBytesArray method of the ClsImgData object.
4.) The output file is stored in the variable img2 under ProcessImgFROMBytesArray method.
What is 'nativeImage' field ?
http://stackoverflow.com/questions/19975734/how-can-i-extract-the-image-out-of-system-drawing-bitmap-to-file-via-windbg
System.Drawing.Bitmap is a tiny managed object. It wraps a handle returned by the unmanaged GDI+ api, stored in the private nativeImage field.
Comments