0

I have created an asp.net composite control that consist of a Label, Text box and an Image control.I need to display the image in Image control without loosing aspect ratio.Maximum width and height of the image control is 640x480 . all the uploaded images are having resolution greater than 640x480. How can I scale the image to fit within the Image control.Is there any way to accomplish this without re size the image and saving it temporarily ?

5
  • See stackoverflow.com/questions/647377/… for a very similar question Commented Apr 2, 2012 at 9:03
  • Thanks dash. But I am using asp.net Image control. I need to accomplish the same thing, re size the image just for display Commented Apr 2, 2012 at 9:14
  • You can still use your image control; however, the images themselves could be loaded via a handler by setting the source appropriately. Commented Apr 2, 2012 at 10:10
  • thanks dash. I'vs solved the issue by adding some code in OnPreRender.using (System.Drawing.Image MyImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(ImageUrl))) if (MaxWidth != 0 && CurrentWidth > MaxWidth){ CurrentWidth = MaxWidth;ImgCtrl.Attributes.Add("Width", CurrentWidth.ToString());} else if (MaxHeight != 0 && CurrentHeight > MaxHeight){ CurrentHeight = MaxHeight; ImgCtrl.Attributes.Add("Height", CurrentHeight.ToString()); } I used predefined value for MaxWidth and MaxHeight Commented Apr 2, 2012 at 10:21
  • Cool; however, remember the images will still be the same file size, and may not resize as gracefully as you want. Commented Apr 2, 2012 at 10:44

1 Answer 1

0

I was using this css class for client-side resizing of images for my thumbnail display.

.css-class-name{
        max-width: 250px; /*works on some browsers*/ 
        max-height: 183px;
        width: expression(this.width > 250 ? "250px" : true);  
        height: expression(this.height > 183 ? "183px" : true); /*long image handling, */
    }        
/*Source: http://www.fastechws.com/tricks/web/image-max-width-height.php */
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.