我尝试在 Winforms 中显示缓存的位图(出于性能原因)。我有一个问题,因为我无法绘制它。 这个答案中的例子 https://stackoverflow.com/a/6474581/1676819说应该有类似的东西 graphics.DrawCachedBitmap(位图, 0, 0); 我找不到它。
到目前为止我做了什么:
- 我添加了 Presentationcore.dll 作为引用
- 我创建了一个
CachedBitmap
CachedBitmap tempCBm = new CachedBitmap(new BitmapImage(new Uri(@"D:\test.bmp")),BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
我尝试用标准方法画出来(导致错误)
private void CustomPaint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(tempCBm, 0,0);//error }
有人能告诉我我做错了什么吗?非常感谢。
请您参考如下方法:
CachedBitmap无法通过 .NET 获得。这是 GDI+ 的一个特性。使用 Bitmap反而。如果您需要优化性能,则可以使用 unsafe context in C# for faster bitmap access .
这里有一个很好的教程:http://www.codeproject.com/Tips/240428/Work-with-bitmap-faster-with-Csharp .
