我已将此调用确定为高压功能中的瓶颈。
graphics.DrawImage(smallBitmap, x , y);
有没有更快的方法将小的半透明位图混合成更大的半透明位图?
示例用法:
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
largeGraphics.DrawImage(bitmaps[i], locations[i].x , locations[i].y);
}
}
var done = new MemoryStream();
large.Save(done, ImageFormat.Png);
done.Position = 0;
return (done);
DrawImage 调用采用一个小的 32bppPArgb 位图并将它们复制到一个较大的位图中,这些位图的位置不同,并且小位图可能仅部分重叠较大的位图可见区域。两个图像都有半透明的内容,这些内容由 DrawImage 以对输出很重要的方式混合。我已经使用 BitBlt 进行了一些测试,但没有看到显着的速度改进,并且 alpha 混合在我的测试中并没有出现相同的结果。我对任何方法都持开放态度,包括更好地调用 bitblt 或不安全的 c# 代码。