C# GDI+图像加载效率

C# GDI+图像加载效率,c#,image,gdi+,C#,Image,Gdi+,现有的应用程序加载了大量图像缩略图,并将它们旋转/定位到画布上的GDI+图形对象中 它这样做的方式不是很有效,但在我们有向图像添加缩放变换的功能请求之前是可以的 当前代码看起来像 //Images is a collection of ImgInfo, a user defined class //contains the width, height, offsets, scale factors, and rotation //in addition to a Bitmap thumbnail

现有的应用程序加载了大量图像缩略图,并将它们旋转/定位到画布上的GDI+图形对象中

它这样做的方式不是很有效,但在我们有向图像添加缩放变换的功能请求之前是可以的

当前代码看起来像

//Images is a collection of ImgInfo, a user defined class
//contains the width, height, offsets, scale factors, and rotation
//in addition to a Bitmap thumbnail.
foreach (var imgInfo in Images)
{
    var imgRect = new Rectangle(0, 0, imgInfo.Width, imgInfo.Height);
    int dx = imgInfo.XOffset, dy = imgInfo.YOffset;

    //Transform the canvas to the drawing coordinate system
    graphics.TranslateTransform(dx, dy);
    graphics.ScaleTransform(1 / (float)imgInfo.ScaleX, 1 / (float)imgInfo.ScaleY);
    graphics.RotateTransform(-imgInfo.Rotation);
    //Center the image
    graphics.TranslateTransform(-imgInfo.Width / 2, -imgInfo.Height / 2);

    graphics.DrawImage(imgInfo.Thumbnail, imgRect);

    //Transform back to the display coordinate system
    graphics.TranslateTransform(imgInfo.Width / 2, imgInfo.Height / 2);
    graphics.RotateTransform(imgInfo.Rotation);
    graphics.ScaleTransform((float)imgInfo.ScaleX, (float)imgInfo.ScaleY);
    graphics.TranslateTransform(-dx, -dy);
}
我怀疑原因如下。假设我有1000个缩略图,绘制第999个缩略图将导致平移、旋转和缩放到目前为止绘制的所有998个图像。只要我们不使用缩放变换,这就没那么糟糕了——我想系统已经针对旋转进行了优化


所以问题是,优化这个的方法是什么?

事实证明,这个问题不是尺度变换。问题是代码在GUI呈现期间引入了异常。由于异常处理是扩展性的,因此存在上述性能问题。在检查日志之前,我们没有意识到这个问题,因为GUI呈现中出现异常后,代码必须继续,因此没有发生异常的明显迹象

绘制999缩略图将导致平移、旋转和缩放到目前为止绘制的所有998图像。为什么会这样?添加图像时会发生什么变化?如果您有2.5k rep,那么您现在应该知道优化此图像的方法是什么?太宽了。嗯。。。2.5k代表没有任何意义。仅仅因为你是第一个被问到常见问题的人,一个幸运的帖子就可以获得数十亿张选票。不管怎样,我一直在学习。如果这个范围太广,你有什么建议?在这种情况下,我应该问一下如何更有效地使用GDI+api吗?