I have a method that I call and it returns bitmap data from a capture device.
It returns a pointer to the buffer data as an IntPtr and the buffer length as an int.
I know in advance that this bitmap is a 24bpp and its width and height.
The problem is that the buffer contains the bitmap data upside down and I need this data to be in the right order (reverse it).
What I do is create a for loop and using CopyMemory, I copy each line (stride) of this data from bottom to up to a newly allocated memory space.
Is there any way to make it faster than creating more memory each time I receive a new frame? It makes the application get a bit slow and consumes more memory as each bitmap is pretty big.
I do this because I use another component that analyses the bitmaps and it doesn’t work propertly if the bitmaps are upside down.
I’m using .net, c#
thanks!
If you have instance of System.Graphics.Bitmap class, you could have used RotateFlip(RotateFlipType.RotateNoneFlipY) – but even if you created Bitmap from your pointer to buffer data, flipped it with mentioned method and passed pointer to bitmap data elsewhere, I think that would be slower than your approach.
But can’t you just swap first line with last, (first+1) with (last-1), etc, without allocating new memory?