public byte[] imagereduce(System.Drawing.Image imgInput, int maxImageSize)
{
int tWidth;
int tHeight;
double widthHeightRatio = (double)imgInput.Width / (double)imgInput.Height;
// If width greater than height, then width should be max image size, otherwise height should be.
// Image should keep the same proportions.
//tWidth = maxImageSize;
//tHeight = (int)(maxImageSize / widthHeightRatio);
if (widthHeightRatio > 1.0)
{
tWidth = maxImageSize;
tHeight = (int)(maxImageSize / widthHeightRatio);
}
else
{
tWidth = (int)(maxImageSize * widthHeightRatio);
tHeight = maxImageSize;
}
//Session["imgheight"] = tHeight;
//Session["imgwidth"] = tWidth;
System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
System.Drawing.Image myThumbnail = imgInput.GetThumbnailImage(tWidth, tHeight, myCallBack, IntPtr.Zero);
//myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
myThumbnail.Save(ms, ImageFormat.Jpeg);
byte[] bitmapData = ms.ToArray();
return bitmapData;
}
public bool ThumbnailCallback()
{
return false;
}