/// <Summary>
/// Generate a thumbnail
/// </Summary>
/// <Param name = "imgBuffer"> source image byte [] </param>
/// <Param name = "width"> width of the generated thumbnail </param>
/// <Param name = "height"> height of the generated thumbnail </param>
/// <Returns> </returns>
Private byte [] GenerateThumbImg (byte [] imgBuffer, int width, int height)
{
MemoryStream imgStream = null;
MemoryStream thumbStream = new MemoryStream ();;
System. Drawing. Image img = null;
System. Drawing. Image thumbImg = null;
System. Drawing. Graphics g = null;
Try
{
ImgStream = new MemoryStream (imgBuffer );
Img = System. Drawing. Image. FromStream (imgStream );
ThumbImg = new System. Drawing. Bitmap (img, width, height );
G = System. Drawing. Graphics. FromImage (thumbImg );
// Set the painting quality of the canvas
G. CompositingQuality = System. Drawing. Drawing2D. CompositingQuality. HighQuality;
G. SmoothingMode = System. Drawing. Drawing2D. SmoothingMode. HighQuality;
G. InterpolationMode = System. Drawing. Drawing2D. InterpolationMode. HighQualityBicubic;
G. DrawImage (thumbImg, 0, 0, width, height );
/* G. DrawImage (img, new System. Drawing. Rectangle (0, 0, width, height ),
0, 0, width, height, System. Drawing. GraphicsUnit. Pixel );*/
ThumbImg. Save (thumbStream, System. Drawing. Imaging. ImageFormat. Jpeg );
Return thumbStream. ToArray ();
}
Catch (Exception ex)
{
Return null;
}
Finally
{
If (g! = Null)
G. Dispose ();
If (thumbImg! = Null)
ThumbImg. Dispose ();
If (img! = Null)
Img. Dispose ();
If (thumbStream! = Null)
ThumbStream. Close ();
If (imgStream! = Null)
ImgStream. Close ();
}
}