Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:33:48+00:00 2026-06-14T19:33:48+00:00

In .NET you usually use the Bitmap class to store images. To access it

  • 0

In .NET you usually use the Bitmap class to store images. To access it quickly, you need to call lock() and unlock() to copy the contents of the bitmap into memory. So, does it mean that the bitmap was not stored in a packed memory array before locking?

Exactly what is the need for locking?, i.e. why couldn’t the platform simply return a pointer to the first pixel of the bitmap and let you access the pixels directly? (apart from the “unsafe” memory access considerations)

Some possible reasons:

  • The bitmap is stored in its original compressed form to save memory (PNG, JPEG, etc)
  • The bitmap is stored in 24-bpp format so its slower to access than a 32-bpp image
  • The bitmap is not stored in a packed memory array and is fragmented so can’t be read/written fast
  • The bitmap is stored in an undisclosed manner, and the platform does not want you to access the actual bitmap data memory – forcing you to create a copy of it in memory using lock()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:33:49+00:00Added an answer on June 14, 2026 at 7:33 pm

    Bitmaps are read in a lazy fashion. The actual algorithm used depends a great deal on the image format, a .bmp file is easy, a .jpeg is not so easy. Under the hood, GDI+ creates a memory mapped file to map the file data into RAM, when necessary, taking advantage of the demand-paged virtual memory mapping feature of the operating system. It is this MMF that infamously creates a lock on the file and is responsible for the ratty exceptions you get when trying to save an image back to a file with the same name.

    Bitmap.LockBits() creates a separate buffer that maps the pixel data from the MMF to an area in memory that has the requested pixel format. Now you have the data in a well defined format that’s independent from the format in the file. Calling UnlockBits() writes the modified data back, if any. Exactly how the data from the file gets re-combined with the modified pixels is not specified and is likely to depend a great deal on the codec.

    This exact same locking happens, unseen, when you use the bitmap in other methods. Like when you draw the image with Graphics.DrawImage(). And infamously when you use Bitmap.GetPixel(). As you can guess by now, there’s a fair amount of overhead involved in getting the pixel data converted at the lock call, the reason that GetPixel() is so slow since you do it for every pixel in the bitmap rather than just once, as DrawImage and LockBits() do.

    It should be also clear that the amount of overhead depends a great deal on the image file format, the expense of decoding the pixel data on-the-fly, the amount of caching done by the decoder, the pixel format of the file versus the pixel format you ask for in LockBits(). There’s way too much going on here to make predictable perf guesses, you’ll have to profile it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use jQuery icons in my asp.net mvc project. Usually I use gray icons
I usually use ASP.net web forms for GUI, maybe one of most stateful technologies.
In my silverlight I have the need to modify PDF files. I usually use
I usually use .Net but now I'm playing Scala in IntelliJ 10.5.1. It's interesting
I usually create ASP.NET websites and have a few classes I use, mainly a
In asp.net, if you use a custom attribute, usually it is rendered as-is. Considering
I usually use the Ruby on Rails framework but for this project I need
Possible Duplicate: Why always close Database connection? I usually use VS2010 and ASP.NET to
In ASP.NET I usually use pageLoad() JavaScript function, that gets executed every time the
Is there any way to use any of .net's table types (usually used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.