Questions tagged [lockbits]

Part of .NET's System.Drawing Namespace - Bitmap.LockBits Method

Locks a Bitmap into system memory

Docs: https://docs.microsoft.com/en-us/dotnet/api/system.drawing.bitmap.lockbits?view=netframework-4.7

93 questions
13
votes
4 answers

Recognizing image within image in C#

I'd like to find an image (needle) within an image (haystack). To keep things simple I take two screenshots of my desktop. One full size (haystack) and a tiny one (needle). I then loop through the haystack image and try to find the needle…
fanti
  • 1,689
  • 3
  • 15
  • 30
9
votes
7 answers

LockBits appears to be too slow for my needs - alternatives?

I'm working on 10 megapixel images taken by a video camera. The aim is to register in a matrix (a two-dimensional array) the grayscale values for each pixel. I first used GetPixel but it took 25 seconds to do it. Now I use Lockbits but it sill takes…
Elo Monval
  • 91
  • 3
6
votes
1 answer

Mifare Ultralight: lock specific pages

I got reference from this link (Mifare Ultralight C Lock) to make all pages on a Mifare Ultralight tag read-only. I can write a message on a Mifare Ultralight tag successfully on Android. Now I want to lock pages 4 to 7 (or any specific page). The…
Minn Thein
  • 81
  • 3
6
votes
1 answer

Read and write directly to Unlocked Bitmap unmanaged memory (Scan0)

Is that ok to Write and Read directly from a unlocked Bitmap unmanaged memory? Can I keep using the BitmapData after I UnlockBits of the Bitmap? I did a test app where I can read the pixel of the Bitmap of a PictureBox at mouse position while…
Pedro77
  • 4,773
  • 7
  • 50
  • 82
6
votes
2 answers

Does Bitmap.LockBits "pin" a bitmap into memory?

I'm using locked bitmaps a lot recently, and I keep getting "attempted to access invalid memory" errors. This is mostly because the bitmap has been moved in memory. Some people using GCHandle.Alloc() to allocate memory in the CLR and pin it. Does…
Robin Rodricks
  • 99,791
  • 133
  • 372
  • 575
6
votes
1 answer

Is it safe (pun intended) to copy bitmap regions using lockbits this way?

I think I've found a MUCH faster way to copy bitmaps in c#. (If it's valid, I'm sure I wasn't the first but I haven't seen it anywhere yet.) The simplest way I can think to ask this is to assert what I based my idea on and if no one shoots holes in…
AppFzx
  • 1,335
  • 2
  • 13
  • 23
4
votes
2 answers

Why do my images seem to be in the format of Bgra instead of Argb?

So, I am very confused over a quick test that I just ran. I am doing some image processing in C#. Get/SetPixel() have proven to be too slow, so I am using LockBits to get at the raw data. However, I seem to have hit a situation which I can't…
Ed S.
  • 115,705
  • 20
  • 165
  • 244
4
votes
1 answer

Why is the random pixel color not so random in my C# application?

I set up a code to randomly cover a bitmap 2 different colors, 7 out of 10 times the color would be blue, and 3 out of 10 times, the color would be green. However, when it's done it looks very un-random, like it decided to put 7 blue pixels a few…
GunnarJ
  • 430
  • 4
  • 11
4
votes
1 answer

How do I permanently lock specific data pages in a MIFARE Ultralight C tag?

I have successfully written some data on data pages 30 to 38. After that I want to lock those pages in order to prevent further writing. The write lock should be permanent, so even if someone knows the authentication key, they should not be able to…
Kamran Shahid
  • 3,232
  • 3
  • 30
  • 70
4
votes
4 answers

Faster Image Processing than Lock Bits

I've been working on an edge detection program in C#, and to make it run faster, I recently made it use lock bits. However, lockBits is still not as fast as I would like it to run. Although the problem could be my general algorithm, I'm also…
vkoves
  • 149
  • 2
  • 9
4
votes
1 answer

Is fixed required with lockbits?

I have some code which has the error "AccessViolationException was unhandled by user code: Attempted to read or write protected memory..." A trimmed down version of the offending function is as follows: protected override void OnPaint(PaintEventArgs…
AppFzx
  • 1,335
  • 2
  • 13
  • 23
3
votes
1 answer

Bitmap LockBits on Android?

My program on Android uses an algorithm that uses a lot of setPixel and getPixel, therefore, it's very slow. On .NET, I can use LockBits to make it faster. Is there LockBits or similar on Java or Android? EDIT: After some searches, I found…
Luke Vo
  • 12,823
  • 19
  • 79
  • 132
3
votes
2 answers

Using LockBits generates weird image

I'm trying to write out a grayscale image using Lockbits, my current code looks is /// /// Save the content of the FrameProc out to a bitmap /// public void Save(string path) { Bitmap bmp = new Bitmap(this.size.Width,…
Phyx
  • 2,667
  • 1
  • 18
  • 35
3
votes
5 answers

C# LockBits perfomance (int[,] to byte[])

Graphics g; using (var bmp = new Bitmap(_frame, _height, PixelFormat.Format24bppRgb)) { var data = bmp.LockBits(new Rectangle(0, 0, _frame, _height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); var bmpWidth = data.Stride; var…
Kir
  • 155
  • 2
  • 10
3
votes
1 answer

Improve speed of video correction algorithm based on locked bitmap, getpixel and optimized auxiliary functions

I wrote this code to remove annoying patterns in a video due to camera malfunction. The problem is that to encode a 2 Minute video this algorithm needs more than 2 hours. I want to significantly reduce the time needed. The algorithm iterates over…
Fabien Biller
  • 125
  • 1
  • 9
1
2 3 4 5 6 7