Groups | Blog | Home
all groups > dotnet drawing api > march 2007 >

dotnet drawing api : Draw multiple resolution images on a PictureBox



active
3/21/2007 9:36:55 PM
One reads an image from a file that has, maybe, a resolution of 300 PPI.
And another image that is 600ppi.
And Draw them it onto a PictureBox.Image that has a 96ppi resolution.

How does one go about maintaining the correct size (inches)
(I don't know the correct term to describe this kind of size.)
I mean, suppose the two images are 5x7 inches at different resolutions.

How to go about it so that the result on the PictureBox is two images that
are the same size, each aprox 5x7.


Thanks in advance



Oliver Sturm
3/22/2007 3:27:58 PM
Hello ,

[quoted text, click to view]

Sounds like you'll just have to calculate :-)

If your image is 5 inches wide and has a resolution of 300dpi, then it is
1500 pixels wide. If the screen has a resolution of 96dpi, then it uses up
5*96=480 pixels for a 5 inch wide surface. So you have to scale your image
down from 1500 pixels to 480 pixels width and you'll be fine. Calculate
the height the same way, and the two values for the other image with the
600pdi resolution as well, and you should have the result you want.


Oliver Sturm
--
active
3/22/2007 4:13:23 PM
If I put a 600 ppi image into the Image property won't it display very
large?

Thanks

[quoted text, click to view]

active
3/22/2007 4:23:49 PM
Thanks, I can do the calculations but wondered if images had imbedded in
them info about their size that would essentially cause the conversion to
the display.

So if I have a file containing an image intended for a printer I really
can't display it without some pixel merging or it will display much bigger
then it will print.

Also, there is a thing called GraphicsUnit which I thought might be helpful.

Thanks



[quoted text, click to view]

Oliver Sturm
3/22/2007 4:26:24 PM
Hello Bob,

[quoted text, click to view]

Well yes, that's a different matter :-)


Oliver Sturm
--
Bob Powell [MVP]
3/22/2007 5:16:36 PM
Why do you imagine you have to draw them??

Put them in the Image property!

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
Oliver Sturm
3/22/2007 8:34:31 PM
Hello,

[quoted text, click to view]

I believe that is in fact the case with many common graphics formats, but
I don't know anything about the details. This would also vary with the
format you use.

[quoted text, click to view]

It wouldn't "cause" it - I don't think there's a standard control
available that would automatically read that info and do the scaling and
displaying for you. But of course that information could be used for your
purpose - I was actually assuming when I read your original question that
you already had that info, probably from the source we were just discussing.

[quoted text, click to view]

Right. Of course. If the image contains far more pixel information than
you can display on your screen, there's really nothing you can do about
it, other dropping or merging some of it.



Oliver Sturm
--
active
3/22/2007 9:00:12 PM
Thanks

[quoted text, click to view]

active
3/22/2007 9:05:58 PM
Thanks, I'll try that right now.


[quoted text, click to view]

Oliver Sturm
3/22/2007 11:29:41 PM
[quoted text, click to view]

You learn something new every day :-)


Oliver Sturm
--
Bob Powell [MVP]
3/23/2007 12:14:57 AM
The point is that GDI+ does indeed do the scaling for you.

If you use DrawImage without the full specification of source ad
destination rectangle the software takes the resolution into account
automatically.

In fact, I think you're the first person I've seen who has complained
about the size issue and not said "I have an image with 2000 * 3000
pixels, why does it draw so small??"

Try drawing the image with DrawImage(image,x,y) and see.

Oh, and stop using CreateGraphics and stop overriding PictureBox paint..
try this instead...

Bitmap bm=new Bitmap(500,500);
Graphics g=Graphics.FromImage(bm);
g.DrawImage(<your high res image>,0,0);
pictureBox1.Image=bm;


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
active
3/23/2007 10:30:02 AM
Bob, is some of the vs2005 help wrong? for example:

Graphics.DrawImage Method (Image, Point[])
Draws the specified Image at the specified location and with the specified
shape and size.

There is no specified size, and what does specified shape mean?
=========New subject=========

The VS doc says for the one you specified:
Graphics.DrawImage Method (Image, Int32, Int32)
Draws the specified image, using its original physical size, at the location
specified by a coordinate pair.
I believe that Scales the image using (Screen DPI/ Image DPI) so it appears
on the screen with the correct (inches) dimension. Correct?


There is also one that

Graphics.DrawImageUnscaled Method (Image, Point)
Draws a specified image using its original physical size at a specified
location.

The text is the same, does it do the same thing?



I realize now that I asked you for the wrong thing last time.

I really (now) want the image to fit in the (500,500) bitmap in your example
below. That is, either the height or width should be 500. I know about

Graphics.DrawImage Method (Image, Single, Single, Single, Single)

Draws the specified Image at the specified location and with the specified
size.

Is that the best way to go (where the width=500 and the Height<=500, or
width<=500 and the Height=500)



Thanks a lot





[quoted text, click to view]

active
5/6/2007 9:43:12 AM

[quoted text, click to view]


I don't want to put words into your mouth but from reading your stuff I've
learned to put most graphics code into the paint event so that it will
persist if re-painting is required.

Is the reason for your statement above because PictureBox insures the Image
object persists?

Thanks

Bob Powell [MVP]
5/8/2007 12:51:55 AM
PictureBox is the most misused control of all time. Why? well, because the
old VB6 PictureBox was a gizmo that behaved like a drawing canvas and now,
naturally, all ex VB developers who use VB.NET think that it's a general
purpose drawing surface. Nothing is further from the truth.

PictureBox displays images, in a simplistic and rather limited way, and
that's all.

See my site for details.
--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


[quoted text, click to view]
AddThis Social Bookmark Button