Bitmap and Graphics

A

Andrew

Hi,

I'm trying to blit small bitmaps onto a larger bitmap, and I've got a
few issues wrt positioning and output size.
I think my problems are due to DPI differences...


My small images are 72 DPI
My Large image (which i need to create in code) needs to be 300 DPI.

My code as it stands (with no accounting for dpi) is:

Bitmap bmp = new Bitmap(600, 600);
Graphics gfx = Graphics.FromImage(bmp);
Bitmap bmpTemp = new Bitmap(strPath);
gfx.DrawImage(bmpTemp, 0, 0);
pictureBox1.Image = bmp;


That works, but if i add the line:
bmp.SetResolution(300, 300);

the displayed image becomes massive. Is this because setting the
picturebox's image property with a bitmap object, does not take dpi into
account? If so, (or otherwise) how do i get the image to display correctly?

Also, the coordinates at which I place smaller image within the larger,
do not appear to take dpi into account. What adjustment do i need to
perform to place things in the correct place?


For example, If i place a 60x60 image at 0,0; and another 60x60 image at
60,60; the second overlaps the first :(

How do i correct this?

Thanks

Andrew
 
A

Andrew

Michael said:
Can't you just do?:

gfx.DrawImage(bmpTemp, 0, 0, 600, 600);

Michael


erm.... What for?


I get a similar problem when using a printing document in 1200 dpi.

I try to draw my image on it and it comes up some random size :s


Andrew
 
J

John B

Andrew said:
Hi,

I'm trying to blit small bitmaps onto a larger bitmap, and I've got a
few issues wrt positioning and output size.
I think my problems are due to DPI differences...


My small images are 72 DPI
My Large image (which i need to create in code) needs to be 300 DPI.

My code as it stands (with no accounting for dpi) is:

Bitmap bmp = new Bitmap(600, 600);
Graphics gfx = Graphics.FromImage(bmp);
Bitmap bmpTemp = new Bitmap(strPath);
gfx.DrawImage(bmpTemp, 0, 0);
pictureBox1.Image = bmp;


That works, but if i add the line:
bmp.SetResolution(300, 300);

the displayed image becomes massive. Is this because setting the
picturebox's image property with a bitmap object, does not take dpi into
account? If so, (or otherwise) how do i get the image to display correctly?

Also, the coordinates at which I place smaller image within the larger,
do not appear to take dpi into account. What adjustment do i need to
perform to place things in the correct place?


For example, If i place a 60x60 image at 0,0; and another 60x60 image at
60,60; the second overlaps the first :(

How do i correct this?

Thanks

Andrew

Call Bitmap.SetResolution on each of your images so that the resolution
is the same for each if this is the effect you desire.

What is happening is that when you draw the 72dpi image onto the 300dpi
image it is scaling it to the same resolution ie 60px gets scaled to
250px to cater for the conversion from 72 to 300 dpi.

The "default" dpi for images also appears to be 96 in vs .net2.0.

JB
 

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