A
A
Alexander Volkov2015-12-19 12:20:50
C++ / C#
Alexander Volkov, 2015-12-19 12:20:50

How to get rid of the "Bitmap area is already locked" error?

Hello!
I work with the Bitmap class.
on the line
Bitmap ImageBitmap = new Bitmap(img);
The program throws an error:
An unhandled exception of type 'System.InvalidOperationException' in System.Drawing.dll
Additional information: The bitmap region is already locked.
A possible reason is that I work simultaneously with two Bitmaps?

using (var wr = new ImageWrapper((Bitmap)img))
            {
                //бинаризация
                foreach(var p in wr)
                    wr[p]=wr[p].GetBrightness()>treshold_Otsu(img) ? Color.White : Color.Black;
            }
            return img;

The treshold_Otsu function also works with Bitmap.
Perhaps someone has already come across a similar one? I didn't find answers on the Internet (maybe I didn't search well)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Volkov, 2015-12-19
@AlexanderAm

The error is completely idiotic, it is enough to assign the value of treshold_Otsu to some variable.
I'm sorry for the inconvenience.
Time is running out so nerves are on edge)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question