Android gets thumbnails of videos and Images

Source: Internet
Author: User

1. When displaying the video image list and sending a multimedia message, you must display the thumbnail of the video or image when creating a slide. The display code is as follows:

// Import
Import Android. content. contentresolver;
Import Android. content. contenturis;
Import Android. Graphics. Bitmap;
Import Android. provider. mediastore. video;
Import Android. widget. imageview;

// Imageview Control
Private imageview mimagepreview;

//.............................

// Initialize imageview
Mimagepreview = (imageview) findviewbyid (R. Id. image_preview );

// Video is the URI of the video file.
Long id = contenturis. parseid (video );
Contentresolver mcontentresolver = mcontext. getcontentresolver ();

// Thumbnail type: mini_kind full_screen_kind micro_kind
Bitmap minithumb = video. thumbnails. getthumbnail (mcontentresolver, ID,
Video. thumbnails. mini_kind, null );
// Fill the image
Mimagepreview. setimagebitmap (minithumb );

//...............................

Or use

Bitmap bitmap = videoattachmentview. createvideothumbnail (mcontext, video );

2 In Android. provider. mediastore contains various processing classes for images and videos, android. provider. mediastore. images. thumbnails and Android. provider. mediastore. video. thumbnails provides a method for generating thumbnails for images and videos.

3. The image and video indexes and their relationship to the corresponding thumbnails are stored in the DB file in/sdcard/data/COM. Android. providers. Media/databases,

Images and thumbnails

Images

_ Id image ID

_ DATA image path

Thumbnails

_ ID: ID of the thumbnail

_ DATA thumbnail storage location

Image_id corresponds to the source image ID

Video table images and thumbnails

Video

_ Id video ID

_ DATA video path

Videothumbnails

_ ID: ID of the video thumbnail

_ DATA video thumbnail storage location

Image_id corresponds to the video ID

4. Take obtaining the thumbnail of a video as an example. The procedure is as follows:

1. Obtain the video Uri.

2. convert it to string to get the video ID.

3. Go to the videothumbnails table and find the video thumbnail path.

4. Obtain the image by path

5. For more information, see: Get thumbnails of images and videos on Android phones.

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.