I. Technical Overview: 1. Ajax does not need to upload images. For more information, see my article (jquery + C # ashx) 2. C # Bitmap Processing System. Drawing. 3. The latest demo supports IE7, IE8, and Firefox. Ii. How to Deal with thumbnail: Core Method for generating a thumbnail: Createthumbnailpicture ///
/// Image thumbnail Processing /// /// /// /// /// Public static void createthumbnailpicture (string srcpath, string destpath, int width, int height) { // Obtain the image object of the source image based on the absolute path of the image Disk System. Drawing. Image IMG = system. Drawing. image. fromfile (srcpath ); // BMP: the thumbnail bitmap object to be created. bitmap BMP = new Bitmap (width, height ); // G: draws a BMP graphics object. Graphics G = graphics. fromimage (BMP ); G. Clear (color. Transparent ); // Initialize necessary parameters for the graphics g object, which is easy to understand. G. pixeloffsetmode = system. Drawing. drawing2d. pixeloffsetmode. highquality; G. interpolationmode = system. Drawing. drawing2d. interpolationmode. High; G. smoothingmode = system. Drawing. drawing2d. smoothingmode. highquality; G. compositingquality = system. Drawing. drawing2d. compositingquality. highquality; // Source image width and height Int imgwidth = IMG. width; Int imgheight = IMG. height; // Draw a thumbnail G. drawimage (IMG, new system. drawing. rectangle (0, 0, width, height), new system. drawing. rectangle (0, 0, imgwidth, imgheight), graphicsunit. pixel ); Imageformat format = IMG. rawformat; Imagecodecinfo info = imagecodecinfo. getimageencoders (). singleordefault (I => I. formatid = format. guid ); Encoderparameter Param = new encoderparameter (system. Drawing. imaging. encoder. Quality, 100l ); Encoderparameters parameters = new encoderparameters (1 ); Parameters. Param [0] = Param; IMG. Dispose (); // Save the generated thumbnail. Here, the GIF format is converted to PNG format. If (format = imageformat. GIF) { Destpath = destpath. tolower (). Replace (". GIF", ". PNG "); BMP. Save (destpath, imageformat. PNG ); } Else { If (info! = NULL) { BMP. Save (destpath, info, parameters ); } Else { BMP. Save (destpath, format ); } } IMG. Dispose (); G. Dispose (); BMP. Dispose (); } |