Re: Is this a known bug with the Bitmap class??

From: Chris R. Timmons (crtimmons_at_X_NOSPAM_Xcrtimmonsinc.com)
Date: 07/08/04


Date: Wed, 07 Jul 2004 22:18:03 -0700


"TCR" <thereagans97@verizon.net> wrote in
news:Pv2Hc.39137$MT5.13387@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;
    }
  }
}


Relevant Pages

  • Re: Copying Format1bppIndexed Images
    ... Either the image is a NULL reference or the Graphics is a NULL reference. ... I suggest that you try to save the 1bpp image as a bitmap and then try to ... > GdipDrawImageRect(HandleRef graphics, HandleRef image, Int32 x, Int32 y, ... >> Assuming that your source image has a resolution of 204 DPI by 196 DPI, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Print Preview (again?)
    ... > the discrepancy of bitmap sizes between the screen and print-outs. ... > You have a screen with some resolution, ... > As for the second copy of the text, in a much larger font, we will have to ... > called the hardware margin - and it must also be taken into consideration. ...
    (microsoft.public.vc.mfc)
  • Re: Print Preview (again?)
    ... > the discrepancy of bitmap sizes between the screen and print-outs. ... > You have a screen with some resolution, ... > As for the second copy of the text, in a much larger font, we will have to ... > called the hardware margin - and it must also be taken into consideration. ...
    (microsoft.public.vc.mfc)
  • Re: Print Preview (again?)
    ... >> resolution is for all of the screen, and the printer resolution is per ... Thus the very small bitmap. ... >> As for the second copy of the text, in a much larger font, we will have ... >> StretchBlt is then used to render the bitmap to the output device. ...
    (microsoft.public.vc.mfc)
  • Re: Office 2001 --> office 2004
    ... "placeable header", usually a low-resolution bitmap. ... resolution, ...  the issues in graphics between 2001 and 2004 were never ... McGhie Information Engineering Pty Ltdhttp://jgmcghie.fastmail.com.au/ ...
    (microsoft.public.mac.office.word)