I've stored my images in SQL server, and imageContent is a byte array (which contains image data stored in DB). I use following code to create a thumbnail from my main image, currently I set explicit width and height for my thumbnail (40x40), but it will damage my image aspect ratio, how can I find aspect ratio of original image and scale down it so that my original aspect ratio is unchanged?
Stream str = new MemoryStream((Byte[])imageContent);
Bitmap loBMP = new Bitmap(str);
Bitmap bmpOut = new Bitmap(40, 40);
Graphics g = Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(Brushes.White, 0, 0, 40, 40);
g.DrawImage(loBMP, 0, 0, 40, 40);
MemoryStream ms = new MemoryStream();
bmpOut.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] bmpBytes = ms.GetBuffer();
bmpOut.Dispose();
//end new
Response.ContentType = img_type;
Response.BinaryWrite(bmpBytes);//imageContent,bmpBytes