HighTechTalks DotNet Forums  

Draw multiple resolution images on a PictureBox

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Draw multiple resolution images on a PictureBox in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
active
 
Posts: n/a

Default Draw multiple resolution images on a PictureBox - 03-21-2007 , 10:36 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





Reply With Quote
  #2  
Old   
Oliver Sturm
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 11:27 AM






Hello ,

Quote:
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.
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
--
http://www.sturmnet.org/blog


Reply With Quote
  #3  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 12:16 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.





Oliver Sturm wrote:
Quote:
Hello ,

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.

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

Reply With Quote
  #4  
Old   
Oliver Sturm
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 12:26 PM



Hello Bob,

Quote:
Why do you imagine you have to draw them??

Put them in the Image property!
Well yes, that's a different matter :-)


Oliver Sturm
--
http://www.sturmnet.org/blog


Reply With Quote
  #5  
Old   
Oliver Sturm
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 04:34 PM



Hello,

Quote:
Thanks, I can do the calculations but wondered if images had imbedded in
them info about their size
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.

Quote:
that would essentially cause the conversion to the display.
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.

Quote:
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.
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
--
http://www.sturmnet.org/blog


Reply With Quote
  #6  
Old   
active
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 05:13 PM



If I put a 600 ppi image into the Image property won't it display very
large?

Thanks

"Bob Powell [MVP]" <bob (AT) _spamkiller_bobpowell (DOT) net> wrote

Quote:
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.





Oliver Sturm wrote:
Hello ,

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.

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



Reply With Quote
  #7  
Old   
active
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 05:23 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



"Oliver Sturm" <oliver (AT) sturmnet (DOT) org> wrote

Quote:
Hello ,

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.

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
--
http://www.sturmnet.org/blog



Reply With Quote
  #8  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 07:14 PM



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.





Oliver Sturm wrote:
Quote:
Hello,

Thanks, I can do the calculations but wondered if images had imbedded
in them info about their size

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.

that would essentially cause the conversion to the display.

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.

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.

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

Reply With Quote
  #9  
Old   
Oliver Sturm
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 07:29 PM



Quote:
If you use DrawImage without the full specification of source ad
destination rectangle the software takes the resolution into account
automatically.
You learn something new every day :-)


Oliver Sturm
--
http://www.sturmnet.org/blog


Reply With Quote
  #10  
Old   
active
 
Posts: n/a

Default Re: Draw multiple resolution images on a PictureBox - 03-22-2007 , 10:00 PM



Thanks

"Oliver Sturm" <oliver (AT) sturmnet (DOT) org> wrote

Quote:
Hello,

Thanks, I can do the calculations but wondered if images had imbedded in
them info about their size

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.

that would essentially cause the conversion to the display.

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.

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.

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
--
http://www.sturmnet.org/blog



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.