Difference between bitmap and bitmapdata

c#, image

Solution

`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.

Problem

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

Original source