Answered by:
Image Resizing and Displaying issues

Question
-
User192985886 posted
Hello all,
I have a website that allows images for an item to be uploaded, pretty typical...
The users aren't good with resizing before upload, also typical...
Some photos are portrait (400x300) and some are landscape (300x400)
When I display them currently, my asp:image controls make them all display as sat 100x75 with a java script function to display them in a main image onmouseover at the 400x300 size.
Does anyone have advice on how to make them display with the correct orientation and also be able to do a mouseover and have it maintain the proper aspect ratio?
Tuesday, January 19, 2010 12:48 AM
Answers
-
User-925286913 posted
Its possible. But, picture quality will not be as good.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 20, 2010 12:02 AM
All replies
-
User-925286913 posted
If you want to disaply them with correct sizes, you need to restrict user to upload images of specific size (400 x 300) only.
You also need to same original (big) and small version to show at default and mouse over positions.
Resize images:
http://weblogs.asp.net/gunnarpeipman/archive/2009/04/02/resizing-images-without-loss-of-quality.aspx
http://forums.asp.net/t/1085119.aspx
http://www.west-wind.com/Weblog/posts/283.aspx
Tuesday, January 19, 2010 4:33 AM -
User192985886 posted
So, no way to handle if there are pictures oriented vertically?
I was thinking maybe I could set the mainimage for mouseover size on mouseover too....but Im not great with javascripting
Tuesday, January 19, 2010 12:04 PM -
User-925286913 posted
Its possible. But, picture quality will not be as good.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, January 20, 2010 12:02 AM -
User1211441112 posted
Try this. I think this will help u
using System.Drawing;
using System.Drawing.Drawing2D;public void ResizeStream(int imageSize, Stream filePath, string outputPath)
{
var image = Image.FromStream(filePath);int thumbnailSize = imageSize;
int newWidth, newHeight;if (image.Width > image.Height)
{
newWidth = thumbnailSize;
newHeight = image.Height * thumbnailSize / image.Width;
}
else
{
newWidth = image.Width * thumbnailSize / image.Height;
newHeight = thumbnailSize;
}var thumbnailBitmap = new Bitmap(newWidth, newHeight);
var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbnailGraph.DrawImage(image, imageRectangle);thumbnailBitmap.Save(outputPath, image.RawFormat);
thumbnailGraph.Dispose();
thumbnailBitmap.Dispose();
image.Dispose();
}Thursday, January 21, 2010 12:07 AM