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 7996191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:38:47+00:00 2026-06-04T14:38:47+00:00

MSDN reference: [1] http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx#Y1178 From the link it says that the first argument will

  • 0

MSDN reference: [1] http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx#Y1178

From the link it says that the first argument will “specifies the portion of the Bitmap to lock” which I set to be a smaller part of the Bitmap (Bitmap is 500×500, my rectangle is (0,0,50,50)) however the returned BitmapData has stride of 1500 (=500*3) so basically every scan will still scan through the whole picture horizontally. However, what I want is only the top left 50×50 part of the bitmap.

How does this work out?

  • 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-04T14:38:48+00:00Added an answer on June 4, 2026 at 2:38 pm

    The stride will always be of the full bitmap, but the Scan0 property will be different according to the start point of the lock rectangle, as well as the Height and Width of the BitmapData.

    The reason for that is that you will still need to know the real bit-width of the bitmap, in order to iterate over the rows (add stride to address).

    A simple way to go about it would be:

    var bitmap = new Bitmap(100, 100);
    
    var data = bitmap.LockBits(new Rectangle(0, 0, 10, 10),
                               ImageLockMode.ReadWrite,
                               bitmap.PixelFormat);
    
    var pt = (byte*)data.Scan0;
    var bpp = data.Stride / bitmap.Width;
    
    for (var y = 0; y < data.Height; y++)
    {
        // This is why real scan-width is important to have!
        var row = pt + (y * data.Stride);
    
        for (var x = 0; x < data.Width; x++)
        {
            var pixel = row + x * bpp;
    
            for (var bit = 0; bit < bpp; bit++)
            {
                var pixelComponent = pixel[bit];
            }
        }
    }
    
    bitmap.UnlockBits(data);
    

    So it is basically really just locking the whole bitmap, but giving you a pointer to the top-left pixel of the rectangle in the bitmap, and setting the scan’s width and height appropriately.

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

Sidebar

Related Questions

I used this white paper from MS for reference: http://msdn.microsoft.com/en-us/library/ms345117(v=sql.90).aspx However I get an
I found this: http://msdn.microsoft.com/en-us/library/vslangproj80.reference3%28VS.80%29.aspx what I have in mind is that many of the
I'm using this as a reference: http://msdn.microsoft.com/en-us/library/dd182449(v=VS.85).aspx So the implementation is very similar. I'm
Reading through this MSDN article http://msdn.microsoft.com/en-us/library/dd460648.aspx I'm seeing a claim that MEF doesn't have
I am trying to follow this example: http://msdn.microsoft.com/en-us/library/aa179614%28SQL.80%29.aspx# It says to add the following
I looked at http://msdn.microsoft.com/en-us/library/7tas5c80.aspx for reference and it makes sense as far as editable
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
According to the docs: http://msdn.microsoft.com/en-us/library/x13ttww7.aspx : The volatile keyword can be applied to reference
From http://msdn.microsoft.com/en-us/library/system.io.memorystream%28v=VS.90%29.aspx : Memory streams created with an unsigned byte array provide a non-resizable
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx Executes the specified delegate on the thread that owns the control's underlying window

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.