GDI + is quite useful.
1> image needs a CLSID parameter to save the image, which can be obtained as follows:
[CPP]View plaincopy
- Int getencoderclsid (const wchar * format, CLSID * pclsid)
- {
- Uint num = 0; // Number of image encoders
- Uint size = 0; // size of the image encoder array in bytes
- Imagecodecinfo * pimagecodecinfo = NULL;
- Getimageencoderssize (& num, & size );
- If (size = 0)
- Return-1; // failure
- Pimagecodecinfo = (imagecodecinfo *) (malloc (size ));
- If (pimagecodecinfo = NULL)
- Return-1; // failure
- Getimageencoders (Num, size, pimagecodecinfo );
- For (uint J = 0; j <num; ++ J)
- {
- If (wcscmp (pimagecodecinfo [J]. mimetype, format) = 0)
- {
- * Pclsid = pimagecodecinfo [J]. CLSID;
- Free (pimagecodecinfo );
- Return J; // success
- }
- }
- Free (pimagecodecinfo );
- Return-1; // failure
- }
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
- // Save to file
- Encoderparameters;
- // Construct the encoding parameter list
- // The array contains only one encoderparameter object
- Encoderparameters. Count = 1;
- Encoderparameters. Parameter [0]. guid = encoderquality;
- // The parameter type is long.
- Encoderparameters. Parameter [0]. type = encoderparametervaluetypelong;
- // Set only one parameter
- Encoderparameters. Parameter [0]. numberofvalues = 1;
- Ulong quality;
- // The quality of the compressed JPEG image is 80% of the original
- Quality = 80;
- 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
- Bool qimgprocess: createthumb (int cx, qbuf & out)
- {
- Assert (m_pimg! = NULL );
- // Create a thumbnail
- Int nwidth = m_pimg-> getwidth ();
- If (CX> = nwidth)
- {
- Return true;
- }
- Int nheight = m_pimg-> getheight ();
- Int nthumbheight = nheight * CX/m_pimg-> getwidth ();
- Bitmap bitmap (CX, nthumbheight, pixelformat24bpprgb );
- Graphics graph (& Bitmap );
- Graph. drawimage (m_pimg, rect (0, 0, CX, nthumbheight ));
- ......
- }
Use GDI + to easily create thumbnails