Setting DPI for PNG

Mar 31, 2010 at 11:23 AM
Edited Mar 31, 2010 at 11:24 AM

I need help on how to set the Horizontal and Vertical DPI property when saving a canvas as png.

Coordinator
Mar 31, 2010 at 11:46 AM
There is no possiblity at the moment, but perhaps I can implement a solution the next days.
Apr 23, 2010 at 7:55 AM

When will this feature be available?

 

Coordinator
Apr 25, 2010 at 8:45 AM
I started with the development, but I didnt find a tool to read the dpi
information for an image (png, jpeg, gif). Do you know such an application?
Apr 26, 2010 at 10:55 AM

The fuctionality I want to have is to set the DPI of the output image/image to be saved. For now, the default dpi is set to 96 for both horizontal and vertical.

Coordinator
Apr 27, 2010 at 10:55 AM

Yes, I know.

 

Which image format do you use? PNG should be no problem, but I use a nother library for JPEG and it seems, that they do not support setting the dpi.

Apr 28, 2010 at 1:57 AM

We are using PNG to save the canvas. Will this functionality be also available for othe image formats e.g. tif, gif, bmp etc.? 

Is setting the DPI now available for the PNG?

Coordinator
Apr 28, 2010 at 7:11 AM
As I told you, I am still looking for an application, where i can read
the png information with for testing. Writing the dpi for png's is
already implemented but not tested, therefore I sent you the code with
an UNTESTED version, which you can test, when you want.
Apr 28, 2010 at 7:29 AM

I have checked your updated solution. I am now able to set the dpi property of the PNG, unfortunately when I checked the output image, the DPI property is not exactly equal to the value that I set. (e.g. Set Value: 300; Output Value: 299.1).

Another is that the quality of the image is the same for the different DPI values. I'm expecting a high quality PNG output for higher DPI settings. 

Coordinator
Apr 28, 2010 at 7:49 AM
Am 28.04.2010 08:29, schrieb jaypee_m_malayao:

From: jaypee_m_malayao

I have checked your updated solution. I am now able to set the dpi property of the PNG, unfortunately when I checked the output image, the DPI property is not exactly equal to the value that I set. (e.g. Set Value: 300; Output Value: 299.1).

Thanks a lot for testing. How did you test the output png to have a correct dpi? Which application do u use?

Another is that the quality of the image is the same for the different DPI values. I'm expecting a high quality PNG output for higher DPI settings.

Hehe and how should this work?

Think about how it works.

(1) I create a writeablebitmap with silverlight.
(2) With this bitmap I create an image.
(3) I save the image to the file / stream.

In step (1) I convert the vector graphic (silverlight canvas) to a pixel graphic (writeablebitmap) and it is not possible to improve the image quality. So what u have to do: Create a temporary control, which the dimension and content you want, create a writeable bitmap for this control and save the bitmap to the file.
Coordinator
Apr 28, 2010 at 7:57 AM
I found a solution for you.

// Pass a scale transform, so that your final scaled image has the right
dimension.
WriteableBitmap bitmap = new WriteableBitmap(myUIElement, new
ScaleTransform { ScaleX = 3, ScaleY = 3 });

ImageTools.Image img = bitmap.ToImage();
img.DensityX = 300;
img.DensityY = 300;

// Save your image.
Apr 28, 2010 at 11:39 AM

Thanks for the solution but we have implemented this approach before and this is not the solution we're looking for. With this approch since we rescale the image, the dimensions of the output image is bigger than the actual dimensions designed in the XAML.

 

Coordinator
Apr 28, 2010 at 1:27 PM
Yes, but when you also set the dpi to a high value (for example the
default dpi is 96, so use a scaling factor of 2 and set the dpi 192),
the resulting image will have the same size (when printing, not at the
pc) but a much better quality.

Sorry, but there is no other solution.