Android GIF image display problems

Source: Internet
Author: User

 

Many people have provided solutions to display GIF images on Android. There are two main types. One is to enable the GIF decoder to decode the GIF when the program is running, and extract and display the frames in the GIF. Another method is to scatter GIF frames into n images using tools in advance, and switch and load the images in the program for display. Both methods can solve the problem of displaying some GIF images.

In practical applications, some very strange GIF images are incomplete, and these frames need to be merged and displayed on the basis of the previous frames. This may cause problems when such an image is extracted and displayed separately. When a bird flies in the forest, the effect becomes the first one to show the forest and then a bird in the blank background, if the height and coordinates of the frame where the bird is located are not properly processed, the displayed bird may be stretched to fill the imageview area.

 

The solution is actually very simple. frames must be consecutive rather than a single frame. In addition, the coordinates and width and height of frames must be extracted and applied to the display of frames.

 

After a GIF file is converted into a byte stream, 7 or 8 bytes indicate the GIF frame width, and 9 or 10 bytes indicate the height of the GIF frame. 1 and 2 bytes of the image data block represent the X coordinate offset, 3 and 4 bytes represent the Y coordinate offset, and 5, 6, and 7 and 8 represent the width and height of the current frame, respectively.

 

 

 Byte [] bytes = stream. tobytearray ();
Int width = bytes [8] <8 | bytes [7]; // GIF box width
Int Height = bytes [10] <8 | bytes [9]; // GIF box height

 

 

 

When an image is displayed, the image is displayed in a stacked manner. When the image is drawn, the image is calculated in the drawing area of the container Based on the container rectangle, GIF rectangle, and frame rectangle information. In addition, remember that when the frame is converted to BMP, the color is argb, which can retain transparency and other effects.

This is because the company's project code is not publicly available for download.

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.