Marshal.Copy and copying a Bitmap

  • Thread starter Thread starter Jerry Q
  • Start date Start date
Jerry,

That document refers to using the Scan0 property on the BitmapData
instance returned to you from the call to LockBits.

Hope this helps.
 
Yes it does, but there are also lot's of code in Internet that uses those
Classes and objects in manyways. Methods of those classes have also
very complex parameters and many kind of conversions must be made.

It would be more painless to have proper example from Microsoft becuse
their GDI+ classes haven't any kind of support for this operation.

Cheers!

Nicholas Paldino said:
Jerry,

That document refers to using the Scan0 property on the BitmapData
instance returned to you from the call to LockBits.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jerry Q said:
Hello,

Where could aI find a sample code which would show how to use
Marshal.Copy to copy a "graphics image" to pixel based image?

There is a MS (really) quick supportpage for that
http://support.microsoft.com/kb/814675/en-us
but it is too approximate for anything.

Cheers!
 
Here is an example to fill in, you can also copy out.

Public Shared Sub FillBitmap(ByVal bmp As Bitmap, ByVal imgArray As Byte())
Dim h As Integer = bmp.Height

Dim bmpDat As Imaging.BitmapData
Dim stride As Integer

Try
bmpDat = bmp.LockBits(New Rectangle(0, 0, bmp.Width,
bmp.Height), _
Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat)

stride = bmpDat.Stride

Marshal.Copy(imgArray, 0, bmpDat.Scan0, stride * h)

Catch ex As Exception
Finally
bmp.UnlockBits(bmpDat)
End Try

End Sub

Jerry Q said:
Yes it does, but there are also lot's of code in Internet that uses those
Classes and objects in manyways. Methods of those classes have also
very complex parameters and many kind of conversions must be made.

It would be more painless to have proper example from Microsoft becuse
their GDI+ classes haven't any kind of support for this operation.

Cheers!

Nicholas Paldino said:
Jerry,

That document refers to using the Scan0 property on the BitmapData
instance returned to you from the call to LockBits.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jerry Q said:
Hello,

Where could aI find a sample code which would show how to use
Marshal.Copy to copy a "graphics image" to pixel based image?

There is a MS (really) quick supportpage for that
http://support.microsoft.com/kb/814675/en-us
but it is too approximate for anything.

Cheers!
 
Back
Top