Android get video, picture thumbnail of concrete implementation _android

Source: Internet
Author: User

1, get video thumbnails have two methods (1) through the content provider to get (2) people to create thumbnails

(1) The disadvantage is that the media library must be updated to see the latest video thumbnails

[Java]

Copy Code code as follows:

/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap Getvideothumbnail (context context, Contentresolver CR, String videopath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Video.Media.DATA, mediastore.video.media._id,};
String Whereclause = MediaStore.Video.Media.DATA + "= '" + Videopath + "'";
Cursor Cursor = testcr.query (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String Videopath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {

int _idcolumn = Cursor.getcolumnindex (mediastore.video.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Video.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
Videopath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Video.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}

/**
* @param context
* @param cr
* @param Videopath
* @return
*/
public static Bitmap Getvideothumbnail (context context, Contentresolver CR, String videopath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Video.Media.DATA, mediastore.video.media._id,};
String Whereclause = MediaStore.Video.Media.DATA + "= '" + Videopath + "'";
Cursor Cursor = testcr.query (MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String Videopath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {

int _idcolumn = Cursor.getcolumnindex (mediastore.video.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Video.Media.DATA);
do {
_id = Cursor.getint (_idcolumn);
Videopath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Video.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
(2) People spend a little time creating thumbnails


[Java]
Copy Code code as follows:

/**
* Get video thumbnails
* @param Videopath
* @param width
* @param height
* @param kind
* @return
*/
Private Bitmap Getvideothumbnail (String videopath, int width, int height, int kind) {
Bitmap Bitmap = null;
Bitmap = Thumbnailutils.createvideothumbnail (Videopath, kind);
Bitmap = Thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input);
return bitmap;
}

/**
* Get video thumbnails
* @param Videopath
* @param width
* @param height
* @param kind
* @return
*/
Private Bitmap Getvideothumbnail (String videopath, int width, int height, int kind) {
Bitmap Bitmap = null;
Bitmap = Thumbnailutils.createvideothumbnail (Videopath, kind);
Bitmap = Thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input);
return bitmap;
}


2. Thumbnail image

[Java]

Copy Code code as follows:

/**
*
* @param context
* @param cr
* @param ImagePath
* @return
*/
public static Bitmap Getimagethumbnail (context context, Contentresolver CR, String ImagePath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Images.Media.DATA, mediastore.images.media._id,};
String Whereclause = MediaStore.Images.Media.DATA + "= '" + ImagePath + "'";
Cursor Cursor = testcr.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String ImagePath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {

int _idcolumn = Cursor.getcolumnindex (mediastore.images.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Images.Media.DATA);

do {
_id = Cursor.getint (_idcolumn);
ImagePath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Images.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}

/**
*
* @param context
* @param cr
* @param ImagePath
* @return
*/
public static Bitmap Getimagethumbnail (context context, Contentresolver CR, String ImagePath) {
Contentresolver TESTCR = Context.getcontentresolver ();
string[] projection = {MediaStore.Images.Media.DATA, mediastore.images.media._id,};
String Whereclause = MediaStore.Images.Media.DATA + "= '" + ImagePath + "'";
Cursor Cursor = testcr.query (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, Whereclause,
NULL, NULL);
int _id = 0;
String ImagePath = "";
if (cursor = NULL | | cursor.getcount () = 0) {
return null;
}
if (Cursor.movetofirst ()) {

int _idcolumn = Cursor.getcolumnindex (mediastore.images.media._id);
int _datacolumn = Cursor.getcolumnindex (MediaStore.Images.Media.DATA);

do {
_id = Cursor.getint (_idcolumn);
ImagePath = cursor.getstring (_datacolumn);
while (Cursor.movetonext ());
}
Cursor.close ();
Bitmapfactory.options Options = new Bitmapfactory.options ();
Options.indither = false;
Options.inpreferredconfig = Bitmap.Config.RGB_565;
Bitmap Bitmap = MediaStore.Images.Thumbnails.getThumbnail (CR, _id, Images.Thumbnails.MINI_KIND,
Options);
return bitmap;
}

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.