Can someone explain the BitmapData.Scan0 property?

This property is a strange one, I made two copies of a bitmap file, included both files as resources, and loaded the resources into bitmap and bitmapdata objects as follows:

        Dim b As New Bitmap(My.Resources.pic1)     ' from bmp file pic1
        Dim b2 As New Bitmap(My.Resources.pic2)   ' from exact copy of pic1 picture file

        Dim r As New Rectangle(0, 0, b.Width, b.Height)

        Dim bd As BitmapData
        bd = b.LockBits(r, ImageLockMode.ReadOnly, b.PixelFormat)
        Dim bd2 As BitmapData
        bd2 = b2.LockBits(r, ImageLockMode.ReadOnly, b2.PixelFormat)

I was trying to cheat and do an Equals on the two bitmapdata objects to see if they were the same picture, but they turn out to be unequal.  Putting a breakpoint after the above, code,I see that the only difference is the Scan0 property, for which one has a value of 62935008 and the other has a value of 62944688.  I guess I don't really understand what this property is, and how they ended up different.  MSDN says Scan0:

"Gets or sets the address of the first pixel data in the bitmap. This can also be thought of as the first scan line in the bitmap."

I read this and assumed that it was an address relative to the first byte of the object, maybe a header length or something.  It would seem weird if it was its own actual location in memory... does anyone know for sure?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
The Scan0 property returns the actual location in memory of the first pixel so it makes sense that those two would be different.

If you need a copy then why not just use the Clone() method of your first Bitmap "b"?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
In VB you cannot access directly memory returned by LockBits. You can use this method in C# or C++ which can work with unmanaged pointers. The following article shows how to do this:

Of course, pointers to pixel data in two different bitmaps are different, even if image is the same. Every bitmap keeps it's own copy of pixel data.

You can use Marshal.Copy methods to copy between unmanaged bitmap bits and Byte() array.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.