I apply filters to the incoming image with the request, and then send it back. I process it all now using Bitmap, very convenient, but the performance suffers greatly. Are there any libraries / classes specifically for this purpose?

Conversion from incoming stream to image

var Picture = new Bitmap(listenerContext.Request.InputStream); 

Search by pixels to set a new color. GetPixel low-performing method (I think)

 for (int x = 0; x < bmp.Width; x++) for (int y = 0; y < bmp.Height; y++) { var temp = bmp.GetPixel(x,y); bmp.SetPixel(x,y, Color.FromArgb(temp.A,temp.R,temp.G,temp.B)); } 

Saving pictures in response to a request

 Picture.Save(listenerContext.Response.OutputStream, ImageFormat.Png); 
  • IMHO, OpenCV is a good fit for working with images, but: 1) It’s in c ++; 2). requires effort to study. - Alexander Muksimov
  • 3
    Use LockBits . - Alexander Petrov
  • @Alias ​​and what about? "FastBitmapLib" or "Fast-Bitmap"? I look through nuget, at the first 825 downloads, at the second 1,54k - StriBog
  • @Alias ​​though FastBitmapLib is more recent (11/22/2017) - StriBog
  • @Alias ​​tried both options. In the first one there is no inverse converter from FastBitmap to Bitmap (or not found), while the second uses the FastColor structure in which the alpha channel is lost - StriBog

1 answer 1

It seems to me the easiest way to use FastBitmap , for example this way:

 using(var fastBitmap = bitmap.FastLock()) { fastBitmap.SetPixel(1, 1, Color.Red);//что-то делаем }; 

which is minimally different from using ordinary Bitmap ; and there is no need for a reverse converter - when working, it changes the existing Bitmap on which it was created.