Using system; Using system. drawing; Using system. IO; Using system. Drawing. imaging; Using system. Drawing. drawing2d; Namespace ants. Tools {
Public class image { Public int width {Get; set ;} Public int height {Get; set ;}
Private image (){} Public Image (INT width, int height) { This. width = width; This. Height = height; } Public memorystream gethightthumb (Stream imgdata, string mode_hw_w_h_cut) { Memorystream result = new memorystream (); System. Drawing. image. getthumbnailimageabort mycallback = new system. Drawing. image. getthumbnailimageabort (thumbnailcallback ); Try { System. Drawing. Image originalimage = system. Drawing. image. fromstream (imgdata ); Int X, Y; X = width; Y = height; Int towidth = X; Int toheight = y; Int x = 0; Int y = 0; Int ow = originalimage. width; Int Oh = originalimage. height; Switch (mode_hw_w_h_cut) { Case "HW": // specify the height/width Scaling (may be deformed) break; Case "W": // specify the width, and the height is proportional. Toheight = originalimage. Height * x/originalimage. width; Break; Case "H // specify the height. The width is proportional to towidth = originalimage. Width * Y/originalimage. height; Break; Case "cut ": If (double) originalimage. width/(double) originalimage. Height> (double) towidth/(double) toheight) { Oh = originalimage. height; Ow = originalimage. Height * towidth/toheight; Y = 0; X = (originalimage. Width-ow)/2; } Else { Ow = originalimage. width; Oh = originalimage. Width * Y/towidth; X = 0; Y = (originalimage. Height-OH)/2; } Break; Default: Break; } System. Drawing. Image bitmap = new system. Drawing. Bitmap (towidth, toheight ); System. Drawing. Graphics G = system. Drawing. Graphics. fromimage (Bitmap ); G. interpolationmode = system. Drawing. drawing2d. interpolationmode. highqualitybicubic; G. smoothingmode = system. Drawing. drawing2d. smoothingmode. highquality; G. Clear (system. Drawing. color. Transparent ); G. drawimage (originalimage, new system. Drawing. rectangle (0, 0, towidth, toheight ), New system. Drawing. rectangle (X, Y, ow, oh ), System. Drawing. graphicsunit. pixel ); Bitmap. Save (result, system. Drawing. imaging. imageformat. JPEG ); } Catch { // Do something } Return result; }} } |