. NET

Source: Internet
Author: User

. 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.

 
 
  1. ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);     
  2.    EncoderParameters parameters = new EncoderParameters(1);     
  3.    parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);     
  4.     
  5.    System.Drawing.Image.GetThumbnailImageAbort myCallback =new      
  6.     
  7.    System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);     
  8.    System.Drawing.Image myThumbnail = image.GetThumbnailImage(intNewWidth, intNewHeight,      
  9.     
  10.  myCallback, IntPtr.Zero);     
  11.   myThumbnail.Save(txtNewPath, ici, parameters);    
  12. ImageCodecInfo ici = GetCodecInfo((string)htmimes[mFileExtName]);  
  13.    EncoderParameters parameters = new EncoderParameters(1);  
  14.    parameters.Param[0] = new EncoderParameter(Encoder.Quality,lngDefinition);  
  15.  
  16.    System.Drawing.Image.GetThumbnailImageAbort myCallback =new   
  17.  
  18.    System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);  
  19.    System.Drawing.Image myThumbnail = image.GetThumbnailImage(intNewWidth, intNewHeight,   
  20.  
  21.  myCallback, IntPtr.Zero);  
  22.   myThumbnail.Save(txtNewPath, ici, parameters);  
  23.    

. NET method for generating thumbnails 2. Use Graphics to re-draw images

 
 
  1. ImageCodecInfo ici = GetCodecInfo ((String) Htmimes [mFileExtName]);
  2. EncoderParameters parameters =NewEncoderParameters (1 );
  3. Parameters. Param [0] =NewEncoderParameter (Encoder. Quality, lngDefinition );
  4. Bitmap objNewBitMap =NewBitmap (intNewWidth, intNewHeight, PixelFormat. Format32bppArgb );
  5. // Create a new Graphics object from the specified Image object 
  6. Graphics objGraphics = Graphics. FromImage (objNewBitMap );
  7. // Clear the entire drawing surface and fill it with a transparent background color 
  8. ObjGraphics. Clear (Color. Transparent );
  9. // Draw the original image object at the specified position and by the specified size 
  10. ObjGraphics. DrawImage (image,NewRectangle (0, 0, intNewWidth, intNewHeight ));
  11. ObjNewBitMap. Save (txtNewPath + txtNewFileName +"."+ MFileExtName, ici, parameters );
  12. ImageCodecInfo ici = GetCodecInfo ((String) Htmimes [mFileExtName]);
  13. EncoderParameters parameters =NewEncoderParameters (1 );
  14. Parameters. Param [0] =NewEncoderParameter (Encoder. Quality, lngDefinition );
  15.  
  16. Bitmap objNewBitMap =NewBitmap (intNewWidth, intNewHeight, PixelFormat. Format32bppArgb );
  17. // Create a new Graphics object from the specified Image object 
  18. Graphics objGraphics = Graphics. FromImage (objNewBitMap );
  19. // Clear the entire drawing surface and fill it with a transparent background color 
  20. ObjGraphics. Clear (Color. Transparent );
  21. // Draw the original image object at the specified position and by the specified size 
  22. ObjGraphics. DrawImage (image,NewRectangle (0, 0, intNewWidth, intNewHeight ));
  23. ObjNewBitMap. Save (txtNewPath + txtNewFileName +"."+ MFileExtName, ici, parameters );
  24.  

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.

  1. Implementation of ASP. NET and SQL Server database image storage
  2. ASP. NET database image storage to Sql2000
  3. Implementation of ASP. NET database Image Upload and reading
  4. Analysis on adding watermarks to Images Using ASP. NET (VB)
  5. Several Methods for quick processing of. NET Images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.