Private byte [] Thumbnail (httpcontext context, byte [] bytes)
{
// System. Drawing. Image thumbnail_image = NULL;
System. Drawing. Image original_image = NULL;
System. Drawing. Bitmap final_image = NULL;
System. Drawing. Graphics graphic = NULL;
Stream S = new memorystream (bytes );
Memorystream MS = NULL;
// Retrieve the uploaded Image
Original_image = system. Drawing. image. fromstream (s );
// Calculate the new width and height
Int width = original_image.width;
Int Height = original_image.height;
Int target_width = 100;
Int target_height = 100;
Int new_width, new_height;
Float target_ratio = (float) target_width/(float) target_height;
Float image_ratio = (float) width/(float) height;
If (target_ratio> image_ratio)
{
New_height = target_height;
New_width = (INT) math. Floor (image_ratio * (float) target_height );
}
Else
{
New_height = (INT) math. Floor (float) target_width/image_ratio );
New_width = target_width;
}
New_width = new_width> target_width? Target_width: new_width;
New_height = new_height> target_height? Target_height: new_height;
Final_image = new system. Drawing. Bitmap (target_width, target_height );
Graphic = system. Drawing. Graphics. fromimage (final_image );
Graphic. fillrectangle (new system. drawing. solidbrush (system. drawing. colortranslator. fromhtml ("# eeffff"), new system. drawing. rectangle (0, 0, target_width, target_height ));
Int paste_x = (target_width-new_width)/2;
Int paste_y = (target_height-new_height)/2;
Graphic. interpolationmode = system. Drawing. drawing2d. interpolationmode. highqualitybicubic;
Graphic. drawimage (original_image, paste_x, paste_y, new_width, new_height );
MS = new memorystream ();
// Final_image.maketransparent ();
Final_image.save (MS, system. Drawing. imaging. imageformat. JPEG );
S. Close ();
S. Dispose ();
Return Ms. getbuffer ();
}