You can decrease the time it takes to be a bitmap image in C # manually access the raw data for the image in contrast to the standard process and functions GetPixel SetPixel.

C-Sharp has many functions built-in image processing. Based on the GDI, GDI-Plus is a powerful tool. However, GDI + has its limits. For example, many of you have already noticed that the scan of a bitmap image in Csharp is extremely slow.

The reason it is so slow and GetPixel SetPixelFunctions. Whenever one of these functions is called, the bitmap is locked, the byte access / modification, and the bitmap is unlocked. The repetitive routine of block-release allows an image in C #. Net write so slowly.

The answer is to manually lock the bitmap access and / or modify the bits and finally the publication of the image. In this way, each write and read is not to lock and unlock the whole image. You might be surprised how much this increase is theOperating speed of your image editing.

Here's the source code in C # for a block bitmap:

Rectangle border = new Rectangle (bitmap.Size Point.Empty);

int width = (int) (bounds.Width * sizeof (pixel data));

BitmapData BitmapData = Bitmap.LockBits (Borders, ImageLockMode.readWrite, PixelFormat.Format32bppArgb);

Byte * Pbase = (BYTE *) bitmapData.Scan0.ToPointer ();

Where pixel data is a structure with a variable for each of the values ​​of an ARGBColor.

To access a pixel with the following code:


pixel pixel data * data = (pixel data *) (* width Pbase + y + x * sizeof (pixel data));


Do not forget, if you are ready to unlock the image:


bitmap.UnlockBits (bitmap data);

0 comments