473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Bitmap.LockBits fails to work as advertised..... !?


I dont know if I missed something in documentation,
but I was having a problem with "Bitmap.LockBits" and
was wondering if anyone else has discovered it too.

According to everyones examples including some of
the MVP's website examples, one could use unmanaged
code to manipulate a bitmap by casting the IntPtr from
the Bitmap.LockBits to say an (int*).

The problem I found is that the bitmap would rarely
move around in memory throwing a fault if you were
in the middle of manipulating a bmp.

My application was a cute little scrolling program
doing a 600x800 bmp at about 30fps. It usualy took about
5 to 10minutes before it tanked. (surely directx and
manipulating textures would have been faster, but thats
not the point.)

I found that if I specified the bitmaps data via another
one of the bitmap constructors, then pinning the memory
in the GC then and only then would the program be 100%
stable.

The only thing I know the Bitmap.LockBits does is lock
out a portion of the bitmap to prevent cross threading issues.

Has anyone else had this problem? Any other solutions while
still using pointers to manipulate data?


Mar 1 '07 #1
2 3824
TheMadHatter wrote:
According to everyones examples including some of
the MVP's website examples, one could use unmanaged
code to manipulate a bitmap by casting the IntPtr from
the Bitmap.LockBits to say an (int*).

The problem I found is that the bitmap would rarely
move around in memory throwing a fault if you were
in the middle of manipulating a bmp.
Yes, the bitmap may move around, but that is not a problem as you are
working with a pinned copy of a part of the bitmap data. Or, at least
you should be. If you are trying to manipulate the bitmap data directly,
you would get that problem.
My application was a cute little scrolling program
doing a 600x800 bmp at about 30fps. It usualy took about
5 to 10minutes before it tanked. (surely directx and
manipulating textures would have been faster, but thats
not the point.)

I found that if I specified the bitmaps data via another
one of the bitmap constructors, then pinning the memory
in the GC then and only then would the program be 100%
stable.

The only thing I know the Bitmap.LockBits does is lock
out a portion of the bitmap to prevent cross threading issues.
No, that's not what it does. It copies the data into a memory buffer and
pins the buffer in memory so that the garbage collector won't move it.
The data that you are working with is protected from other threads, but
that is just because the data is local to your thread.

--
Göran Andersson
_____
http://www.guffa.com
Mar 1 '07 #2
No, that's not what it does. It copies the data into a memory buffer and
pins the buffer in memory so that the garbage collector won't move it.
The data that you are working with is protected from other threads, but
that is just because the data is local to your thread.
That's what I thought it was suppose to do, but on a single thread program,
it still managed to move. I used LockBits at the beginning sub on the entire
area of the bmp, then used unlock at the end. I fail to see the flaw in that.

Thanks for the responce.
Mar 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sergio Florez M. | last post by:
How can I convert a Bitmap to a byte array? I've searched all over and none of the code samples I've managed to find work. Actually, I just need to create a Byte array starting from an Image...
2
by: James Dean | last post by:
I create a bitmap like this. The width and height are got from the compressed file i am reading. The width and height are in pixels.....1bpp bitmap = new...
3
by: halise | last post by:
Hi, i am in trouble with an exception in .net platform with c#. The exception thrown is exactly as follows: System.ArgumentException: Invalid parameter used. at...
4
by: Ma Xiaoguang | last post by:
Dear ladies and gentlemen: How to access all the pixels of a bitmap with C#? I am working with Delphi before. In Delphi, you can use TBitmap.Scanline property to access all the pixels of a...
5
by: mallolnolla | last post by:
Hello there, I'm trying to display a grabbed picture from a matrox meteor II to a picturebox (I know I can use the matrox display, but I need to show it on a PictureBox). I've tried to fill the...
5
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
2
by: cosminb | last post by:
I have a native function which returns an image in the form of a BYTE* lpDIB array. How do I convert it to a Bitmap, so that I can work with it properly in C#? Thanks in advance, Cosmin
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
7
by: RB0135 | last post by:
Hi All, I have some Windows BMP, 1BPP, monochrome files that I need to get the raw data from to load a graphics buffer on a Roll Printer (which I know can be done). Lets forget about the Roll...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.