HighTechTalks DotNet Forums  

Problem Loading Image To Form Graphics Object

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


Discuss Problem Loading Image To Form Graphics Object in the Dotnet Framework (Drawing) forum.



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

Default Problem Loading Image To Form Graphics Object - 09-23-2005 , 05:56 PM






I'm trying to display a PNG on a form in my VB.NET application, but it will only display a cropped portion of the image. I'm using the following:

Dim gr As Graphics = Me.CreateGraphics
Dim img As Image = Bitmap.FromFile(<Path to PNG file>)
gr.DrawImage(img, CInt(50), CSng(50), CSng(img.Width), CSng(img.Height))

I've already found that the gr.SetClip is a dummy switch and ClipBounds is read-only. I also tried gr.Clip.MakeInfinite() and gr.Clip.MakeEmpty(), but again neither changed the observed clipping in any way.

Question:
How can I get the graphics object of the form to display the entire picture on the form, instead of only the top left 3 square inches of it?

Thanks.


Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Problem Loading Image To Form Graphics Object - 09-23-2005 , 06:14 PM






DrawImage has many overloaded methods.

The one that you are using is saying start drawing the image
from the left corner (50,50) of your image to your form.

That is why it is cropped!

You want to draw the entire image. Try the following:

Dim rcSrc As new Rectangle ( 0, 0, img.Width, img.Height )
gr.DrawImage( img, rcSrc )
"Phil Galey" <pagaley (AT) starcalif (DOT) com.nospam> wrote

I'm trying to display a PNG on a form in my VB.NET application, but it will only display a cropped portion of the image. I'm using the following:

Dim gr As Graphics = Me.CreateGraphics
Dim img As Image = Bitmap.FromFile(<Path to PNG file>)
gr.DrawImage(img, CInt(50), CSng(50), CSng(img.Width), CSng(img.Height))

I've already found that the gr.SetClip is a dummy switch and ClipBounds is read-only. I also tried gr.Clip.MakeInfinite() and gr.Clip.MakeEmpty(), but again neither changed the observed clipping in any way.

Question:
How can I get the graphics object of the form to display the entire picture on the form, instead of only the top left 3 square inches of it?

Thanks.

Reply With Quote
  #3  
Old   
Phil Galey
 
Posts: n/a

Default Re: Problem Loading Image To Form Graphics Object - 09-23-2005 , 06:37 PM



Thanks for your reply.

Actually, that's what I tried originally. I pasted your code in just now and it's still giving me only a 3 square inch portion of the picture. It's like the graphics object has clipping bounds set automatically upon creation, and attempts to remove the clipping are so far ineffectual. The one thing that did change with your code is that the upper left corner of the picture now starts at the upper left corner of the form, but the picture is still clipped. And surprisingly, gr.Clip.MakeInfinite doesn't change that either.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

DrawImage has many overloaded methods.

The one that you are using is saying start drawing the image
from the left corner (50,50) of your image to your form.

That is why it is cropped!

You want to draw the entire image. Try the following:

Dim rcSrc As new Rectangle ( 0, 0, img.Width, img.Height )
gr.DrawImage( img, rcSrc )
"Phil Galey" <pagaley (AT) starcalif (DOT) com.nospam> wrote

I'm trying to display a PNG on a form in my VB.NET application, but it will only display a cropped portion of the image. I'm using the following:

Dim gr As Graphics = Me.CreateGraphics
Dim img As Image = Bitmap.FromFile(<Path to PNG file>)
gr.DrawImage(img, CInt(50), CSng(50), CSng(img.Width), CSng(img.Height))

I've already found that the gr.SetClip is a dummy switch and ClipBounds is read-only. I also tried gr.Clip.MakeInfinite() and gr.Clip.MakeEmpty(), but again neither changed the observed clipping in any way.

Question:
How can I get the graphics object of the form to display the entire picture on the form, instead of only the top left 3 square inches of it?

Thanks.


Reply With Quote
  #4  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Problem Loading Image To Form Graphics Object - 09-23-2005 , 06:46 PM



Why don't you try to add a PictureBox to your form
and in the PictureBox paint handler use that graphics object to
draw your image to the PictureBox. That graphics object will
already be formatted for the PictureBox extents. You should
be able to draw the image with no clipping problems.



"Phil Galey" <pagaley (AT) starcalif (DOT) com.nospam> wrote

Thanks for your reply.

Actually, that's what I tried originally. I pasted your code in just now and it's still giving me only a 3 square inch portion of the picture. It's like the graphics object has clipping bounds set automatically upon creation, and attempts to remove the clipping are so far ineffectual. The one thing that did change with your code is that the upper left corner of the picture now starts at the upper left corner of the form, but the picture is still clipped. And surprisingly, gr.Clip.MakeInfinite doesn't change that either.

"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

DrawImage has many overloaded methods.

The one that you are using is saying start drawing the image
from the left corner (50,50) of your image to your form.

That is why it is cropped!

You want to draw the entire image. Try the following:

Dim rcSrc As new Rectangle ( 0, 0, img.Width, img.Height )
gr.DrawImage( img, rcSrc )
"Phil Galey" <pagaley (AT) starcalif (DOT) com.nospam> wrote

I'm trying to display a PNG on a form in my VB.NET application, but it will only display a cropped portion of the image. I'm using the following:

Dim gr As Graphics = Me.CreateGraphics
Dim img As Image = Bitmap.FromFile(<Path to PNG file>)
gr.DrawImage(img, CInt(50), CSng(50), CSng(img.Width), CSng(img.Height))

I've already found that the gr.SetClip is a dummy switch and ClipBounds is read-only. I also tried gr.Clip.MakeInfinite() and gr.Clip.MakeEmpty(), but again neither changed the observed clipping in any way.

Question:
How can I get the graphics object of the form to display the entire picture on the form, instead of only the top left 3 square inches of it?

Thanks.

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 - 2013, Jelsoft Enterprises Ltd.