Windows窗体面板:具有较大尺寸(分辨率)的drawtobitmap c#输出错误 [英] windows form Panel: drawtobitmap with larger size (resolution) c# output error

查看:414
本文介绍了Windows窗体面板:具有较大尺寸(分辨率)的drawtobitmap c#输出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的伙伴们,我一直在寻找这个解决方案的好几个小时。

我使用以下代码从面板成功创建了jpeg文件:

 位图panelImage = new Bitmap(mapPanel.Width,mapPanel.Height) ; 

图形g = Graphics.FromImage((Image)panelImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

mapPanel.DrawToBitmap(panelImage,mapPanel.ClientRectangle);

g.DrawImage(panelImage,0,0,mapPanel.Width,mapPanel.Height);
g.Dispose();

panelImage.Save(saveImageDialog.FileName,ImageFormat.Jpeg);





输出如下(分辨率差)



http://e1302.hizliresim.com/16/5/jtpjy.jpg



然后我试图让分辨率更高代码:

位图panelImage = new Bitmap(3508,2480); 
panelImage.SetResolution(300,300);

图形g = Graphics.FromImage((Image)panelImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

mapPanel.DrawToBitmap(panelImage,mapPanel.ClientRectangle);

g.DrawImage(panelImage,0,0,3508,2480);
g.Dispose();

panelImage.Save(saveImageDialog.FileName,ImageFormat.Jpeg);





但结果如下:

http://e1302.hizliresim.com/16/5/jtny7.jpg



面板区域没有填满整页。



请帮帮我



谢谢

解决方案

Bitmap.SetResolution 不会提高分辨率。这个词有误导性。此参数的更改不会在位图的内容中更改位图的任何内容。它仅填充元数据,显示默认情况下每英寸有多少个点。换句话说,它定义了图像的一些默认缩放比例,例如,可用于打印。请参阅:

记录用户活动 [ ^ ]。



你想要以像素为单位增加位图的大小。您甚至没有尝试这样做:您的位图是3508x2480,然后您尝试将其绘制为3508x2480。没有什么变化。但如果你真的放大图像,结果的质量可能会非常差。实际上,你不能通过相当高的质量来有效地放大图像。更确切地说,有一些智能算法可用于执行此类操作,例如分形压缩 http:/ /en.wikipedia.org/wiki/Fractal_compression [ ^ ];是的,从这个意义上说,压缩可以帮助扩大图像质量更好),但结果仍然有限。这被称为重新采样。



即使像素的大小通常被称为分辨率并且与分辨率有关,事实上,这个东西与分辨率无关。分辨率是能够在想象中单独解析两个单独的功能。让我们说,如果你有一些物体的两个紧密定位的特征,然后用某个镜头和相机制作图像,这两个特征可以看起来模糊在一起或不同。分辨率通常以每毫米(或英寸)的线数来衡量,并表征能够再现一些样本图案,通常是对比直线的周期性图案...



-SA

Dear fellows, I have been searching for hours for this solution.
I successfully create jpeg file from panel with this code:

Bitmap panelImage = new Bitmap(mapPanel.Width, mapPanel.Height);

Graphics g = Graphics.FromImage((Image)panelImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

mapPanel.DrawToBitmap(panelImage, mapPanel.ClientRectangle);

g.DrawImage(panelImage, 0, 0, mapPanel.Width, mapPanel.Height);
g.Dispose();

panelImage.Save(saveImageDialog.FileName, ImageFormat.Jpeg);



the output is as below (the resolution is bad)

http://e1302.hizliresim.com/16/5/jtpjy.jpg

then I tried to make the resolution higer using this code:

Bitmap panelImage = new Bitmap(3508, 2480);
panelImage.SetResolution(300, 300);

Graphics g = Graphics.FromImage((Image)panelImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

mapPanel.DrawToBitmap(panelImage, mapPanel.ClientRectangle);

g.DrawImage(panelImage, 0, 0, 3508, 2480);
g.Dispose();

panelImage.Save(saveImageDialog.FileName, ImageFormat.Jpeg);



but it resulted like this:
http://e1302.hizliresim.com/16/5/jtny7.jpg

the panel area did not fill the whole page.

please help me

thank you

解决方案

Bitmap.SetResolution does not increase resolution. This term is misleading. The change in this parameter does not change anything in the presentation of the bitmap, in its content. It only fills in metadata showing how many dots per inch does it have by default. In other words, it defines some default scaling of the image, which can be used, say, for printing. Please see:
Record User Activity[^].

You want to increase the size of the bitmap in pixels. You are not even trying to do it: your bitmap is 3508x2480, and then you try to draw it as 3508x2480. Nothing changes. But if you really up-scaled the image, the quality of the result could be very poor. Actually, you cannot effectively enlarge the image by a considerable factor with good quality. More exactly, there are some "intellectual" algorithms for doing such things, such as fractal compression (http://en.wikipedia.org/wiki/Fractal_compression[^]; yes, compression, in that sense, can help to enlarge images with better quality), but the results are still limited. And this is called "re-sampling".

Even though the size of the bitmap in pixels is often called "resolution" and is related to resolution, in fact, this stuff has nothing to do with "resolution". Resolution is the ability to resolve two separate features as separate in imagine. Let''s say, if you have two closely located features of some object, and then make an image with certain lens and camera, these two features can look blurred together or distinct. Resolution is usually measured in lines per mm (or inch) and characterized the ability to reproduce some sample pattern, usually a periodic pattern of contrast straight lines…

—SA


这篇关于Windows窗体面板:具有较大尺寸(分辨率)的drawtobitmap c#输出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆