Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bitmap and bitmapdata

Tags:

c#

image

What is the difference between System.Drawing.bitmap and System.Drawing.Imaging.bitmapdata in C#?
How to convert them to each other?

like image 534
Zhr Saghaie Avatar asked Feb 22 '15 06:02

Zhr Saghaie


1 Answers

System.Drawing.Bitmap is an actual bitmap object. You can use it to draw to using a Graphics instance obtained from it, you can display it on the screen, you can save the data to a file, etc.

The System.Drawing.Imaging.BitmapData class is a helper object used when calling the Bitmap.LockBits() method. It contains information about the locked bitmap, which you can use to inspect the pixel data within the bitmap.

You can't really "convert" between the two per se, as they don't represent the same information. You can obtain a BitmapData object from a Bitmap object simply by calling LockBits(). If you have a BitmapData object from some other Bitmap object, you can copy that data to a new Bitmap object by allocating one with the same format as the original, calling LockBits on that one too, and then just copying the bytes from one to the other.

like image 158
Peter Duniho Avatar answered Sep 30 '22 16:09

Peter Duniho