If you are using VB, perhaps this topic is superfluous, because VB has an image control can be very easy to achieve a variety of formats of the image display function, but for VC but not a sample of the control can achieve this effect, how to do? After a period of research, found that only two steps to achieve the work, you can achieve in VC like VB in the same animated GIF dynamic effect.
This article will introduce the two parts is the use of IPicture interface and GIF storage format, as if a storage format, readers do not want to see it! In fact, it is only necessary to use the most basic part of the reader, please look down patiently.
A IPicture interface
The IPicture interface is a COM class whose member functions can be seen in Microsoft's MSDN, where only the following functions are used:
Get_width |
Returns the width of the current image |
Get_height |
Returns the height of the current image |
Render |
Draws the specified image at the specified location, on the device context |
The use of IPicture does not require a CoCreateInstance function, but only the use of OleLoadPicture, which is omitted (because it is not the focus of this article), since this interface is introduced in many articles and magazines.
Two GIF storage format
GIF storage format is a very complex content, if you want to speak thoroughly can write a lot of articles, fortunately, to achieve the theme of this article only need to know one of the image storage structure can be, here to define the image structure for gifimage:
typedef struct gifImage{
WORD logX;
WORD logY;
WORD width;
WORD height;
struct flag{
BYTE d:3;
BYTE c:1;
BYTE b:3;
BYTE a:1;
}Flag;
}GifImage,*PGifImage;
In this structure,
LOGX is the x-coordinate of the upper-left corner of the logical screen, usually 0;
Logy is the y-coordinate of the image relative to the upper-left corner of the logical screen, usually 0;
Width is the breadth of the image;
Height is the altitude of the image;
Flag is a flag, a refers to the existence of the local color palette, b for the storage mode (not related to this topic), C is the RGB value is sorted (independent), d for the size of the palette, for 3*2^ (d+1);
Finally, I want to mention, because each image starts with a 0x2c, and 0x2c front must be 0, so in the storage format to find the starting position of the image, just look up the 0x2c and the previous value of 0 (see the code below), second, a pair of images may be stored as a number of pieces of data, It is important that each data is fast starting with the length of the data. The image is stored as:
0x2c |
Image opening |
Gifimage |
Image head Structure |
BYTE number |
Number is a digital that is related to GIF compression and can be ignored. |
Size of the first pair of images |
|
...... |
Image storage Content |
Image size of the second pair |
|
...... |
|
...... |
|
...... |
|
0x00 |
Data Block End |