以最佳质量缩小 WPF 中的位图
如何将此 GDI 代码转换为 WPF 代码?
Icon bigIcon32x32 = null;
bigIcon32x32 = Icon.ExtractAssociatedIcon("c:\\test.docx");
Bitmap bm = bigIcon32x32.ToBitmap();
Bitmap thumb16x16 = new Bitmap(16, 16);
Graphics graphics = Graphics.FromImage(thumb16x16);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, new Rectangle(0, 0, 16, 16), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel);
graphics.Dispose();
bm.Dispose();
thumb16x16.Dispose();
看来我必须使用 ToBitmap() 方法,但从那时起我只想使用 WPF。
最后,我想通过绑定在 WPF DataGrid 的列中显示小型 16x16 像素图像。
How can I convert this GDI code to WPF code?
Icon bigIcon32x32 = null;
bigIcon32x32 = Icon.ExtractAssociatedIcon("c:\\test.docx");
Bitmap bm = bigIcon32x32.ToBitmap();
Bitmap thumb16x16 = new Bitmap(16, 16);
Graphics graphics = Graphics.FromImage(thumb16x16);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bm, new Rectangle(0, 0, 16, 16), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel);
graphics.Dispose();
bm.Dispose();
thumb16x16.Dispose();
It seems I have to use the ToBitmap() methode but from then on I want to use WPF only.
In the end I want to display small 16x16 pixel Images in a WPF DataGrid`s Column via Binding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 DataGrid 单元格中显示位图,您可以将 DataGridTemplateColumn 与 DataTemplate 结合使用,并使用 IValueConverter 在 DataGrid 单元格中显示图像。
您可以使用 BmpBitmapDecoder 的属性来获得尽可能好的图像。
以下是 XAML 中 DataGrid 的定义:
1-我在 DataGrid 中有三列,第一列是图像。
2-我设置路径=。因为我想做的就是从转换器加载图像。
3- DataGrid 绑定到 ViewModel 中的 Customers 集合,为了完整性,我在最后包含了这些定义。
下面是一次性查找 Word 文档关联图标的转换器。
如果要处理多个图标,请将 BitmapFrame 引用存储在字典中,并使用“value”输入参数来选择要显示的图像。
视图模型在我的视图模型构造函数中加载以下客户集合。
To show a bitmap in a DataGrid cell you can use a DataGridTemplateColumn with a DataTemplate using the IValueConverter to display an image in a DataGrid cell.
You can play with properties of BmpBitmapDecoder to achieve as good an image as possible.
Here is the definition for the DataGrid in XAML:
1- I have three columns in the DataGrid with the first one being the image.
2- I set Path=. because all I wanted to do was load the image from the converter.
3- The DataGrid binds to a Customers collection in a ViewModel, and I included the definitions of those for completeness at the end.
Here is the converter that does a onetime lookup of the Word Doc's associated icon.
If you want to handle multiple icons store the BitmapFrame references in a Dictionary and use the "value" input parameter to select which image to display.
The View Model loads the following collection of Customers my View Model constructor.