How to display original size of picture within image control?

  • Thread starter Thread starter OK
  • Start date Start date
O

OK

I've added an Image control to a page within VS2005.

In case the image is too large for the image control size it sqeezes the
picture in order to show the whole picture.
How can I have the picture not be sqeezed at all?

regards,
Oscar
 
If you don't want the picture to be resized, don't specify a height or width
in the Image Control (and also don't specify a height or width using CSS).
If the image is still being resized for some reason, you can dynamically
determine the dimensions of the picture using the following code:

Dim i As System.Drawing.Image =
System.Drawing.Image.FromFile(MapPath("images/frog.gif"))
MyImage.Width = i.Width & "px"
MyImage.Height = i.Height & "px"

This code will look at the file and get the dimensions, and then set the
Width and Height properties of the Image Control to those values. Hopefully
this helps.
 
Hi Nathan,

thanks for your advice.
In case I remove the height and width specifications, the imagecontrol is
resized to the size of the picture.
All I want is to maintain the size of the image control without any resizing
of the picture. So it might be the case that the picture is shown partly.

regards,
Oscar
 
If I understand you correctly, you are trying to, under certain conditions,
display only part of the picture (in other words, crop it). If this is
correct, I would suggest one of two things:

1. Dynamically create an image by using the System.Drawing classes

2. Place the Image control inside a div, and specify the following CSS
properties for the div:

width:100px;height:100px;overflow:hidden;display:inline-block;

You will obviously use different width and height values, but the
overflow:hidden; prevents anything larger than the specified width and
height from being displayed and the display:inline-block; allows you to
specify a width and height but still keeps the element inline. (Note:
FireFox does not yet support the display:inline-block; property, so you
decide which of my suggestions you want to use). Hopefully this can help
you.
 
Back
Top