Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
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.

C#
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");


Dispose method for C++/CLI:
if (panel1->BackgroundImage!=nullptr)
    delete panel1->BackgroundImage;


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!
Posted
Updated 23-Oct-12 3:56am
v4
Comments
Sergey Alexandrovich Kryukov 23-Oct-12 9:40am    
Why, why saving some content like this as an image, ever?
Why do you think resolution can help? (Probably you simply misuse the term. Resolution is pure metadata; it does not improve quality. Probably you mean dimensions in pixels.)
--SA
christmars 23-Oct-12 9:54am    
To question why: Because what I need is only a picture with a transparent time-label on it. And this is a good way because it's really simple. The idea is to save a panel with all items on it.

To resulotion: No, I didn't mean "resulotion can help". I just want to know the reason, why the pictures have gray dots but not clean. And how can I overcome this. The resolution is anoter question, I want to know, how could I change the resolution of the fotos.

1 solution

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.
 
Share this answer
 
Comments
christmars 24-Oct-12 1:55am    
Thank you very much for your introduction! I would get a closer knowledge about the topic "saving the image". I also think what I did was too simple for saving the image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900