How to display original size of picture within image control?

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
 
N

Nathan Sokalski

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.
 
O

OK

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
 
N

Nathan Sokalski

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top