Use GDI + to easily create a thumbnail.

Source: Internet
Author: User

Use GDI + to easily create a thumbnail.

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

 


How to Create a thumbnail in cs3

The following content is for reference only:

Installation, partitioning, and optimization of Win7 Systems

I. System Installation

1. Use the Chinese version PQ8.05 to delete all partitions.
2. Disconnect the network before installation. Select a custom installation system. On the partition page, press "Shift + F10" and use "Diskpart" to partition.
3. desktop-computer-properties-Device Manager-display adapter-Update driver software-manually find and install the graphics driver software-restart the computer.
4. Enable the super Administrator Account, log out of the computer, log on to the "Administrator" account, Run "Import ACER Certificate" and "Import flagship KEY" as the Administrator, cancel the Administrator account, and disable the Administrator account,
5. After necessary settings and disk fragment on the "control panel", install the computer protection system (remove the boot item) after the rain ).
6. Manually install the system upgrade patch and Jiangmin anti-virus software, and then create a protection system progress (named as: Jiangmin anti-virus software ).
7. install necessary software and create protection system progress (named system application ).

How can I use GDI + to draw a chart based on the specified path?

C # basics of GDI + programming
1. About GDI +
In essence, GDI + provides developers with a set of implementations and various devices (such as monitors, printers, and other devices with graphical capabilities but less than those with graphic details) library functions for interaction. The essence of GDI + is that it can replace developers to achieve interaction with monitors and other peripherals. From the developer's point of view, it is an arduous task to achieve direct interaction with these devices.
1 demonstrate that GDI + plays an important intermediary role between developers and the above-mentioned devices. Among them, GDI + "arranged" almost everything for us-from printing a simple string "HelloWorld" to the console to drawing a straight line, a rectangle or even printing a complete form.

Figure 1.GDI+ plays an important intermediary role
So how does GDI + work? To solve this problem, let's analyze an example-draw a line segment. Essentially, a line segment is a collection of pixels from a starting position (X0, Y0) to an ending position (Xn, Yn. To draw such a line segment, the device (in this example, the monitor) needs to know the corresponding device coordinates or physical coordinates.
However, developers do not directly tell the device, but call the drawLine () method of GDI +, and then, ") draw A straight line from point A to B. GDI + reads the positions of vertices A and vertices B, converts them into A pixel sequence, and the command monitor displays the pixel sequence. In short, GDI + converts independent device calls into a device's understandable form, or converts devices in the opposite direction.
So far, we have briefly understood the working mechanism of GDI +. Now let's start to explore how to implement some basic image operations.
Ii. Image operations-thumbnails, scaling and storage
In this example, we will implement the following tasks:
1. Create a thumbnail.
2. Scale A loaded image.
3. save an image in the operation.
A) create a thumbnail.

Thumbnail is the concentrated version of the image. In typical cases, the size of a thumbnail image is 80x200 pixels. In GDI +, a thumbnail of an Image can be created by using the GetThumbnailImage () method of the Image class. The function prototype is as follows:

Public Image GetThumbnailImage (

Int thumbWidth,

Int thumbHeight,

GetThumbnailImageAbort callback,

IntPtr callbackData

)

The first parameter corresponds to the width of the thumbnail, the second parameter corresponds to the height of the generated thumbnail, and the third parameter is an Image. GetThumbnailImageAbort delegate. This delegate is not used in GDI + 1.0. Even so, you must create a delegate and pass a reference to the delegate in this parameter. The fourth parameter is also not used, but must be provided for compatibility. Note that the fourth parameter must be IntPtr. Zero.
If the first two parameters (that is, the width and height) are both 0, then GDI + returns an embedded thumbnail. Otherwise, use the system-defined size to create the thumbnail. For example, if img is an image class instance and its width and height are all defined by the system, the statement for creating a thumbnail should be as follows:

Image thumbNailImage = img. GetThumbnailImage (0, 0, tnCallBack, IntPtr. Zero );

Here, thumbNailImage contains the thumbnail returned, and tnCallback is a function corresponding to Image. GetThumbnailImageAbort, which is defined as follows:

// It must be called but not used

Style = 'font-size: 10.0pt; font-family: Verdana '> publ... full text>
 

Related Article

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.