Use GDI + to easily create thumbnails

Source: Internet
Author: User

GDI + is quite useful.

 

1> image needs a CLSID parameter to save the image, which can be obtained as follows:

[CPP]View plaincopy
  1. Int getencoderclsid (const wchar * format, CLSID * pclsid)
  2. {
  3. Uint num = 0; // Number of image encoders
  4. Uint size = 0; // size of the image encoder array in bytes
  5. Imagecodecinfo * pimagecodecinfo = NULL;
  6. Getimageencoderssize (& num, & size );
  7. If (size = 0)
  8. Return-1; // failure
  9. Pimagecodecinfo = (imagecodecinfo *) (malloc (size ));
  10. If (pimagecodecinfo = NULL)
  11. Return-1; // failure
  12. Getimageencoders (Num, size, pimagecodecinfo );
  13. For (uint J = 0; j <num; ++ J)
  14. {
  15. If (wcscmp (pimagecodecinfo [J]. mimetype, format) = 0)
  16. {
  17. * Pclsid = pimagecodecinfo [J]. CLSID;
  18. Free (pimagecodecinfo );
  19. Return J; // success
  20. }
  21. }
  22. Free (pimagecodecinfo );
  23. Return-1; // failure
  24. }

 

 

2> image: Another parameter of SAVE, encoderparameters, can be used for image compression * (copied from the Internet)

Using img/JPEG with encoderparameters. Parameter [0]. value can greatly reduce the disk space occupied by image files.

[CPP]View plaincopy
  1. // Save to file
  2. Encoderparameters;
  3. // Construct the encoding parameter list
  4. // The array contains only one encoderparameter object
  5. Encoderparameters. Count = 1;
  6. Encoderparameters. Parameter [0]. guid = encoderquality;
  7. // The parameter type is long.
  8. Encoderparameters. Parameter [0]. type = encoderparametervaluetypelong;
  9. // Set only one parameter
  10. Encoderparameters. Parameter [0]. numberofvalues = 1;
  11. Ulong quality;
  12. // The quality of the compressed JPEG image is 80% of the original
  13. Quality = 80;
  14. Encoderparameters. Parameter [0]. value = & quality;

 

3> about thumbnails

I used the getthumbnailimage of the image, and found that the effect on some images is not ideal (the thumbnail with bright colors is better, but for those images with low color difference and dark color, the effect will be poor ). in this case, graphic and bitmap can be used to directly scale down an image.

[CPP]View plaincopy
  1. Bool qimgprocess: createthumb (int cx, qbuf & out)
  2. {
  3. Assert (m_pimg! = NULL );
  4. // Create a thumbnail
  5. Int nwidth = m_pimg-> getwidth ();
  6. If (CX> = nwidth)
  7. {
  8. Return true;
  9. }
  10. Int nheight = m_pimg-> getheight ();
  11. Int nthumbheight = nheight * CX/m_pimg-> getwidth ();
  12. Bitmap bitmap (CX, nthumbheight, pixelformat24bpprgb );
  13. Graphics graph (& Bitmap );
  14. Graph. drawimage (m_pimg, rect (0, 0, CX, nthumbheight ));
  15. ......
  16. }

 

Use GDI + to easily create thumbnails

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.