Can this tile blitter get faster?

When I make a tile-based map editor in C #, I try to iterate over the X, Y axes and call Graphics.DrawImage () to split one tile in place, from the bitmap on the Bitmap map. It takes several seconds to complete this process, so I only do it once when loading a new map or changing its set. Any changes from there are relatively quick highlights of the edited tile only.

Now I sat back today and thought about my options. Graphics.DrawImage () is the only one of the three (the others are DrawImageUnscaled and DrawImageUnscaledAndCropped (?)), Which allows you to specify the source origin. DrawImageUnscaled () was much more much faster, but always close to the upper left corner of the original bitmap.

Unlike the QuickBasic PSET and POKEing speeds of video memory or VB6 PSet versus WinAPI SetPixel, the simple Get / SetPixel loop was as fast as calling DrawImageUnscaled , but it did a trimming that would otherwise only have performed DrawImage.

It's fast enough, but I was wondering how something like direct image manipulation could speed it up even more? Is there something with LockBits, perhaps a feature that I know almost nothing about?

+4
source share
3 answers

There is a great answer for this. How to manage pixel level images in C #

If you are following the LockBits path, you can post further information on speed differences.

+1
source

Bitting in software seems like a serious bottleneck. I would seriously suggest studying hardware accelerated drawing for such a task.

+1
source

the simple Get / SetPixel loop was as fast as calling DrawImageUnscaled

Then you are definitely doing something wrong. The GetPixel and SetPixel are quite overhead, using any of the DrawImage methods should be something like 100 times faster (if possible if your tiles are very small, for example, 2x2 pixels).

Unlike the name, the DrawImageUnscaled method does not draw without resizing. Instead, it uses the PPI settings of the images to scale them to the same measurements. This means that if you have a bitmap with a setting of 100 PPI and draw a bitmap with a setting of 50 PPI on it, the size will be resized to double.

If you draw images unchanged, you can change the quality settings in the Graphics object to adjust the speed. You can, for example, set the InterpolationMode property to NearestNeighbor so that it does not perform any interpolation.

An alternative to drawing on a bitmap would be to use LockBits and UnlockBits to directly access the bitmap image data.

+1
source

Source: https://habr.com/ru/post/1286153/


All Articles