如何从可视元素生成BMP [英] How to generate a BMP from a visual element
问题描述
亲爱的,
我正在使用第三方WPF组件,它具有将可视元素导出到BMP文件的本机功能。
我遇到的问题是此功能是以屏幕上可见的大小导出BMP(捕获类型)
我需要做的是通过第三方功能获取生成的BMP并以我需要的大小生成一个新的BMP文件。
结果位图可以比最初生成的更大或更小。
什么这是最好的方法吗?
如果我从较小的原始位图生成更大的新位图,我会放弃一些质量吗?
感谢您的帮助和样本
问候
嗨wakefun,
>>这样做的最佳方法是什么?
以下代码供您参考。
Bitmap newImage = new Bitmap(newWidth,newHeight);
使用(Graphics gr = Graphics.FromImage(newImage))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(srcImage,new Rectangle(0,0,newWidth,newHeight));
}
>>如果我从较小的原始位图生成更大的新位图,我会放弃一些质量吗?
是的,它会。
祝你好运,
漳
Dear all,
I am using a third party WPF component which have a native feature to export the visual element to a BMP file.
The problem I have is that this feature is exporting a BMP at the size visible on screen ( Kind of Capture)
What I need to do is to get the generated BMP by third party feature and generate a new BMP file at the size I need.
The result bitmap can be bigger or small that what as been generated initially.
What is the best approach to do that ?
If I generate bigger new bitmap from a smaller original bitmap will I loos some quality ?
Thanks for help and sample
regards
Hi wakefun,
>>What is the best approach to do that ?
The following code for your reference.
Bitmap newImage = new Bitmap(newWidth, newHeight); using (Graphics gr = Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight)); }>>If I generate bigger new bitmap from a smaller original bitmap will I loos some quality ?
Yes, It will.
Best regards,
Zhanglong
这篇关于如何从可视元素生成BMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!