将面板另存为图像:图片不清晰,某些区域出现灰点 [英] Saving panel as an image: Picture not clear, gray dots on some areas

查看:139
本文介绍了将面板另存为图像:图片不清晰,某些区域出现灰点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

首先,让我向您展示我已经拥有的.这可能会帮助想知道的人,如何轻松地将面板另存为图像.

就我而言,我将带有透明标签的图片另存为图像(bmp/jpg).
该图像来自其他窗口,我在其中使用SampleGrabber抓取帧并将其保存到我的硬盘中("C:\\ example.bmp").标签显示了计算机的当前时间.

Hello,

firstly let me show you what I already have. This might help somebody who want to know, how to save a panel as an image easily.

In my case, I save a picture with a transparent label over it as an image (bmp/jpg).
The image comes from other windows , where i used SampleGrabber to grab frames and save them to my harddisc ("C:\\example.bmp"). The label shows the current time of the computer.

label1->Text = Convert::ToString(System::DateTime::Now);
panel1->BackgroundImage = Image::FromFile("C:\\example.bmp");
// loading picture on BackgroundImage allows us to make the label text with a transparent back color(label property-> Back color -> Transparent)

// you can also make a pictureBox on the panel and load Foto on the pictureBox,
// But in this case you have to lay the label separately to the pictureBox on the panel in order to get it showed. Which means, you couldn't make the transparent label overlap the image, as I tried.
System::Drawing::Rectangle rc = panel1->ClientRectangle;
Bitmap^ bmp= gcnew Bitmap(rc.Width, rc.Height);
this->panel1->DrawToBitmap(bmp, rc);

bmp->Save("C:\\ExampleJPG.jpg");
bmp->Save("C:\\ExampleBMP.bmp");



C ++/CLI的处置方法:



Dispose method for C++/CLI:

if (panel1->BackgroundImage!=nullptr)
    delete panel1->BackgroundImage;



好的,现在是我的问题了:
1.最大的问题是保存图片的质量.我可以成功保存图片.但我总是在它们上出现一些灰色点("C:\\ ExampleJPG.jpg"或"C:\\ ExampleBMP.bmp").有时很多,有时只有三个或四个点,有时则没有这样的东西.我不明白为什么.那我应该更正照片吗?还是什么?
你能给我建议吗?

2.另一个问题:如何更改图片的分辨率? (在保存之前或之后.)



OK, now time for my problem:
1. the biggest problem is the quality of saved pictures. I can succesfully save the pictures. But I always get some gray points on them ("C:\\ExampleJPG.jpg" or "C:\\ExampleBMP.bmp"). Sometimes a lot, sometimes only three or four dots, sometimes there is no such things. I don''t understand why. So should I make foto corrections? Or what else?
Could you give me advices?

2. another question: How can I change the resolution of the pictures? (Before or after they are saved.)

Any answer will be appreciated!

推荐答案

问题可能出在保存图像的图像格式中.
JPG有损.它将提供原始图像的视觉近似.不会是每个像素一个像素的完全重复.创建JPG时,确实具有图像质量设置.设置越高,它将越精确.但文件大小也会变大.

BMP文件来的是多种格式.只有24位和32位格式才能保证图像的真实保真度.如果使用较小的位级别,则图像将使用调色板近似原始图片.

最简单的近似是最接近的颜色匹配.它将检查像素,并在调色板中找到最接近原始颜色的颜色.如果原始图像中有很多独特的颜色,则此技术可以产生8位彩色的褪色图像.

8位颜色的常见近似技术是抖动.在这项技术中,我们将色彩匹配与系统结合起来以解决色彩错误.当我们在一行中匹配每种颜色时,我们将原始颜色和替换颜色之间的差异添加到下一个像素,然后再次尝试匹配.我们将这一过程进行到最后.此技术有多种变体,包括用于动画的Z访问抖动.

抖动肯定会在图像中产生伪像.

************************************************

同样,如果您正在做透明胶片,则您的alpha平面中可能会有瑕疵.并检查您应用透明位图的方法.有些方法使用简单的位平面,另一些方法则识别透明级别.
The problem may lay in the image format you''re saving the image in.

JPG is lossy. It will provide a visual approximation of the original image. It will not be a pixel per pixel exact duplicate. when you create the JPG, you do have an image quality setting. The higher the setting , the more accurate it will be. but the file size will be larger also.

BMP files come is a variety of formats. Only the 24 bit and 32 bit formats can guarantee true fidelity of the image. If you use smaller bit levels then the image will approximate the original picture using a color palette.

The simplest approximation is nearest color matching. It will examine a pixel and find the color in the palette that is the closest to the original color. This technique can yield washed out images in 8 bit color, if there is a large number of unique colors in the original image.

A common approximation technique for 8 bit color is dithering. In this technique, we combine color matching with a system to account for color errors. As we match each color in a line, we add the difference between the original color and the replacement one, to the next pixel and attempt the match again. We carry on this process to the end of the line. There are variations to this technique, including Z access dithering for animations.

Dithering will definitely produce artifacts in your images.

********************************************

Also if you''re doing transparencies, you could have artifacts in your alpha plane. And check your method of applying the transparent bitmap. Some methods use a simple bit plane, others recognize levels of transparency.


这篇关于将面板另存为图像:图片不清晰,某些区域出现灰点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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