views:

201

answers:

1

I've used a number of techniques in the past to paint images in Windows.Forms and I'm now revisiting some core libraries that handle rendering skin images for our product. I'm interested in particular in rendering the same image multiple times (tiled) to represent the field of a background control. Assuming the image is exactly the right size (no scaling needed) and contains only the portion to be tiled, what is the fastest method of painting that image to screen?

One of the optimizations I've used is converting the image to PixelFormat.Format32bpp**P**Argb which precalculates some of the alpha channels.

Is there a performance difference between DrawImage and DrawImageUnscaled?

Looking for real world experience rather than documented expectations.

Update: After digging around the framework classes I see that the Control class uses a TextureBrush using the image to be tiled. This looks promising.

+1  A: 

If you're willing to p/invoke, BitBlt. If not, DrawImageUnscaled is just fine.

overslacked
DrawImageUnscaled actually scales the image...how can it be faster than DrawImage?
Paul Alexander
You have that backwards - DrawImageUnscaled will not not scale the image, in fact, there are no parameters to control the size of the target (except by specifying the size of the source).
overslacked
Yeah...wish that were true. The docs state otherwise and testing it shows otherwise. A look at the actual code for DrawImageUnscaled just calls DrawImage directly.
Paul Alexander