. NET method for generating thumbnails 1. Use the GetThumbnailImage method of the Image to directly generate a compressed Image. This is probably the case:
File: // set the EncoderParameters object of the original image object and set the definition.
- ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);
- EncoderParameters parameters = new EncoderParameters(1);
- parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);
-
- System.Drawing.Image.GetThumbnailImageAbort myCallback =new
-
- System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
- System.Drawing.Image myThumbnail = image.GetThumbnailImage(intNewWidth, intNewHeight,
-
- myCallback, IntPtr.Zero);
- myThumbnail.Save(txtNewPath, ici, parameters);
- ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);
- EncoderParameters parameters = new EncoderParameters(1);
- parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);
-
- System.Drawing.Image.GetThumbnailImageAbort myCallback =new
-
- System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
- System.Drawing.Image myThumbnail = image.GetThumbnailImage(intNewWidth, intNewHeight,
-
- myCallback, IntPtr.Zero);
- myThumbnail.Save(txtNewPath, ici, parameters);
-
. NET method for generating thumbnails 2. Use Graphics to re-draw images
- ImageCodecInfo ici = GetCodecInfo ((String) Htmimes [mFileExtName]);
- EncoderParameters parameters =NewEncoderParameters (1 );
- Parameters. Param [0] =NewEncoderParameter (Encoder. Quality, lngDefinition );
- Bitmap objNewBitMap =NewBitmap (intNewWidth, intNewHeight, PixelFormat. Format32bppArgb );
- // Create a new Graphics object from the specified Image object
- Graphics objGraphics = Graphics. FromImage (objNewBitMap );
- // Clear the entire drawing surface and fill it with a transparent background color
- ObjGraphics. Clear (Color. Transparent );
- // Draw the original image object at the specified position and by the specified size
- ObjGraphics. DrawImage (image,NewRectangle (0, 0, intNewWidth, intNewHeight ));
- ObjNewBitMap. Save (txtNewPath + txtNewFileName +"."+ MFileExtName, ici, parameters );
- ImageCodecInfo ici = GetCodecInfo ((String) Htmimes [mFileExtName]);
- EncoderParameters parameters =NewEncoderParameters (1 );
- Parameters. Param [0] =NewEncoderParameter (Encoder. Quality, lngDefinition );
-
- Bitmap objNewBitMap =NewBitmap (intNewWidth, intNewHeight, PixelFormat. Format32bppArgb );
- // Create a new Graphics object from the specified Image object
- Graphics objGraphics = Graphics. FromImage (objNewBitMap );
- // Clear the entire drawing surface and fill it with a transparent background color
- ObjGraphics. Clear (Color. Transparent );
- // Draw the original image object at the specified position and by the specified size
- ObjGraphics. DrawImage (image,NewRectangle (0, 0, intNewWidth, intNewHeight ));
- ObjNewBitMap. Save (txtNewPath + txtNewFileName +"."+ MFileExtName, ici, parameters );
-
Note that lngDefinition is a LONG parameter to adjust the definition. Generally, it is clear from 50 to 90.
. NET generates two kinds of thumbnail effects. Graphics is better in definition (with the same width and height), and Graphics is smaller in rendering, which is about 1/3 smaller.
- Implementation of ASP. NET and SQL Server database image storage
- ASP. NET database image storage to Sql2000
- Implementation of ASP. NET database Image Upload and reading
- Analysis on adding watermarks to Images Using ASP. NET (VB)
- Several Methods for quick processing of. NET Images