Is this a known bug with the Bitmap class??

T

TCR

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.
Thanks,
TCR
 
C

Chris R. Timmons

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;
}
}
}
 
C

cody

I can confirm this because I once had the same problem that sometimes Jpeg
images seems to return the wrong resolution. I will send you my solution
this evening because I have it at home.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top