开发者

Copy Small Bitmaps on to Large Bitmap with Transparency Blend: What is faster than graphics.DrawImage(smallBitmap, x , y)?

开发者 https://www.devze.com 2022-12-23 04:52 出处:网络
I have identified this call as a bottleneck in a high pressure function. graphics.DrawImage(smallBitmap, x , y);

I have identified this call as a bottleneck in a high pressure function.

graphics.DrawImage(smallBitmap, x , y);

Is there a faster way to blend small semi transparent bitmaps into a larger semi transparent one?

Example Usage:

XY[] locations = GetLocs();
     Bitmap[] bitmaps = GetBmps(); //small images sizes vary approx 30px x 30px

        using (Bitmap large = new Bitmap(500, 500, PixelFormat.Format32bppPArgb))
        using (Graphics largeGraphics = Graphics.FromImage(large))
        {
          for(var i=0; i < largeNumber; i++)
          {
            //this is the bottleneck
            large开发者_JS百科Graphics.DrawImage(bitmaps[i], locations[i].x , locations[i].y); 
         }
       }

       var done = new MemoryStream(); 
       large.Save(done, ImageFormat.Png); 
       done.Position = 0;
       return (done);

The DrawImage calls take a small 32bppPArgb bitmaps and copies them into a larger bitmap at locations that vary and the small bitmaps might only partially overlap the larger bitmaps visible area. Both images have semi transparent contents that get blended by DrawImage in a way that is important to the output. I've done some testing with BitBlt but not seen significant speed improvement and the alpha blending didn't come out the same in my tests. I'm open to just about any method including a better call to bitblt or unsafe c# code.


After some testing I see that Dan was right (see comments above). It is possible to beat GDI Draw Image performance if you don't need all the blending features it offers, but in the case of transparency blends I don't think there is room for material improvement.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号