FromImage loading smaller version of image with wrong size

  • Thread starter Thread starter Jon Slaughter
  • Start date Start date
J

Jon Slaughter

I am trying to load an image using From image. All the code work(even a
simple test version such as

Bitmap bitmap;

public Form1()

{

InitializeComponent();

bitmap = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\Jon\My
Documents\Visual Studio 2005\Projects\BMTest1\BMTest1\Earth.png");

}

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint(e);

e.Graphics.DrawImage(bitmap, 0, 0);

e.Graphics.DrawRectangle(Pens.AliceBlue, 0, 0, bitmap.Width, bitmap.Height);

}

}



except for the fact that the image is much smaller than it should be. If I
put the same image in a paint box then it is full size. The rectangle has
over 3 times the size of the bitmap shown by draw image.

Basically my image is 300x300 but the DrawImage function is showing an image
with the size of about 95x95. Of course it has something to do with the
FromFile call I believe and not the Draw Image.

Any one know whats going on? I believe that it might have to do with reading
a thumbnail instead of the actual file as I recall reading someone else
having a similar problem a while back.

Thanks,

Jon
 
I meant right size. The image size is correctly figured but the "bits"
themselfs are a scaled down version.
 
Jon Slaughter said:
Basically my image is 300x300 but the DrawImage function is showing an
image with the size of about 95x95. Of course it has something to do with
the FromFile call I believe and not the Draw Image.

Test it. Console.WriteLine(bitmap.Size);

Then try e.Graphics.DrawImage(bitmap, bitmap.Width, bitmap.Height);
 
Michael C said:
Test it. Console.WriteLine(bitmap.Size);

Then try e.Graphics.DrawImage(bitmap, bitmap.Width, bitmap.Height);

I tried both and same result.
 
Stanimir Stoyanov said:
Jon Slaughter said:
I tried both and same result.

Hello Jon,

Can you check what the horizontal and vertical resolutions of the image
are? Depending on them (the DPI) the image may seem smaller or larger on
displays with different DPI settings.

You can then use the SetResolution method [1] to correct the issue.

[1]
http://msdn2.microsoft.com/en-us/library/system.drawing.bitmap.setresolution(VS.71).aspx


That does fix the problem of scale if I use 100x100 but I chose those
numbers "randomly". Now the questions is how do I set the dpi? Do I need to
get the dpi of the monitor and use that? Seems like a lot of work to display
it with the correct size unless there is a simple way?

When I do use the dpi of the image, which is 300x300 it does go down to the
same scaled version so that does seem to be the issue.

Thanks,
Jon
 
Jon Slaughter said:
That does fix the problem of scale if I use 100x100 but I chose those
numbers "randomly". Now the questions is how do I set the dpi? Do I need
to get the dpi of the monitor and use that? Seems like a lot of work to
display it with the correct size unless there is a simple way?

When I do use the dpi of the image, which is 300x300 it does go down to
the same scaled version so that does seem to be the issue.

Can you answer my first question with something a little more descriptive
that "same result". We still haven't established if the image is loading
with the correct resolution and what is actually happening when you specify
the size you want to draw at.
 
Back
Top