"TCR" <th**********@verizon.net> wrote in
news:Pv*******************@nwrdny01.gnilink.net:
Hi,
I posted this earlier and got a suggestion that didn't pan
out. I am
trying to determine if there is a known bug related to the
resolution value returned when opening a .jpg file by passing
the file path to the bitmap class constructor or by using the
Image.FromImage() static function to return a bitmap object. I
have tried to open a jpeg file to convert its resolution to a
lower value but it doesn't return the proper resolution value
when loading the initial image.. I know the images are 300 X
300 dpi but it reports them as 72 X 72 dpi.
Troy,
The code below works for me. Note that if the image file doesn't
contain any resolution data, then the resolution of the
Bitmap/Graphics image defaults to the resolution of the video screen
(per Charles Petzold in "Programming Windows with C#").
You may want to ask this question again in the
microsoft.public.dotnet.framework.drawing group. There may be some
dotnet image experts there who don't frequent this group.
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
---------------------------------------------------
using System;
using System.Drawing;
namespace Example
{
public class ExampleClass
{
public static int Main(string[] args)
{
// An image known to have 96 dpi.
string imagePath = @"C:\A_96_dpi_image.jpg";
///////////
// Bitmap
///////////
using (Bitmap b = new Bitmap(imagePath))
{
Console.WriteLine("Bitmap b:");
Console.WriteLine(" b.HorizontalResolution = {0}",
b.HorizontalResolution);
Console.WriteLine(" b.VerticalResolution = {0}",
b.VerticalResolution);
Console.WriteLine("");
}
///////////
// Image and Graphics
///////////
Image i = Image.FromFile(imagePath);
using (Graphics g = Graphics.FromImage(i))
{
Console.WriteLine("Graphics g:");
Console.WriteLine(" g.DpiX = {0}", g.DpiX);
Console.WriteLine(" g.DpiY = {0}", g.DpiY);
}
return 0;
}
}
}