How to get Image from other Image quickly
-
I need to divide a very large image (say 5-7 mpx) into smaller pieces (24 bpp Image objects). Algorithm is not a problem, the speed of used GDI+ method is. Using Graphics.DrawImage() is slow, even when no interpolation is done. The problem is not in the count of pieces, but in the size of huge source image. Doesn't matter how large the pieces are, because the long time is taken by the reading of pixels from source. I've thought about using unsafe pixel access, but still hope there's some method for obtaining smaller image from larger one quickly.
-
I need to divide a very large image (say 5-7 mpx) into smaller pieces (24 bpp Image objects). Algorithm is not a problem, the speed of used GDI+ method is. Using Graphics.DrawImage() is slow, even when no interpolation is done. The problem is not in the count of pieces, but in the size of huge source image. Doesn't matter how large the pieces are, because the long time is taken by the reading of pixels from source. I've thought about using unsafe pixel access, but still hope there's some method for obtaining smaller image from larger one quickly.
Libor Tinka wrote:
because the long time is taken by the reading of pixels from source
I wouldn't read pixels. Locate each small piece on the original image and draw it to a separate graphic buffer. Then, you may either save it to a file or render it to the screen.
Best, Jun
-
Libor Tinka wrote:
because the long time is taken by the reading of pixels from source
I wouldn't read pixels. Locate each small piece on the original image and draw it to a separate graphic buffer. Then, you may either save it to a file or render it to the screen.
Best, Jun
The drawing to separate buffer (doesn't matter how small the buffer is) is slow when working with large images. Drawing small area of 10 by 10 pixels from position [x,y] using graphics.DrawImage(srcImage, new Rectangle(0, 0, 10, 10), x, y, 10, 10) looks fast - try it on 7 megapixel image, it won't be.
-
I need to divide a very large image (say 5-7 mpx) into smaller pieces (24 bpp Image objects). Algorithm is not a problem, the speed of used GDI+ method is. Using Graphics.DrawImage() is slow, even when no interpolation is done. The problem is not in the count of pieces, but in the size of huge source image. Doesn't matter how large the pieces are, because the long time is taken by the reading of pixels from source. I've thought about using unsafe pixel access, but still hope there's some method for obtaining smaller image from larger one quickly.
If you want speed then dont use GDI. Use unsafe code. here is an example of using unsae code to handle bitmaps. Does not do what you want, but I am sure you can figure it out :-) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp11152001.asp[^]
My pointless rants meragussa.blogspot.com[^]