Retrieve image thumbnails:
Java code
- Byte [] imagebyte = getimagefromurl (urlpath. Trim ());
- // The following is to convert the image into a thumbnail and then load it
- Bitmapfactory. Options = new bitmapfactory. Options ();
- Options. injustdecodebounds = true;
- Bitmapfactory. decodebytearray (imagebyte, 0, imagebyte. length, <span style = "background-color: RGB (255,255,255);"> options </span>); <span style = "line-Height: 25px; font-size: 14px;
White-space: normal; "> // The returned bitmap is empty </span>
Byte [] imagebyte = getimagefromurl (urlpath. trim (); // The following is to convert the image into a thumbnail and then load bitmapfactory. options = new bitmapfactory. options (); options. injustdecodebounds = true; bitmapfactory. decodebytearray (imagebyte, 0, imagebyte. length, options); // The returned bitmap is null.
Java code
- Options. injustdecodebounds = false;
- Int be = (INT) (options. outheight/(float) 200 );
- If (be <= 0 ){
- Be = 1;
- }
- Options. insamplesize = be;
- Return bitmapfactory. decodebytearray (imagebyte,
0, imagebyte. length, options); // returns a thumbnail.
Options. injustdecodebounds = false; int be = (INT) (options. outheight/(float) 200); If (be <= 0) {Be = 1;} options. insamplesize = be; return bitmapfactory. decodebytearray (imagebyte, 0, imagebyte. length, options); // returns a thumbnail.
Get the video thumbnail:
/**
* Obtain the specified video thumbnail Based on the video URI address.
* @ Param cr
* @ Param URI indicates the URI of the local video.
* @ Return returns bitmap data.
*/
Public static bitmap getvideothumbnail (contentresolver Cr, Uri URI ){
Java code
- Bitmap bitmap = NULL;
- Bitmapfactory. Options = new bitmapfactory. Options ();
- Options. indither = false;
- Options. inpreferredconfig = bitmap. config. argb_8888;
- Cursor cursor = Cr. Query (Uri, new string [] {mediastore. Video. Media. _ id },
Null, null,
Null );
- If (cursor = NULL | cursor. getcount () =
0 ){
- Return NULL;
- }
- Cursor. movetofirst ();
- String videoid = cursor. getstring (cursor. getcolumnindex (mediastore. Video. Media. _ id ));
// Image ID in image table. s
- If (videoid = NULL ){
- Return NULL;
- }
- Cursor. Close ();
- Long videoidlong = long. parselong (videoid );
- Bitmap = mediastore. Video. thumbnails. getthumbnail (Cr, videoidlong, images. thumbnails. micro_kind, options );
- Return bitmap;
- }
Bitmap bitmap = NULL; bitmapfactory. options = new bitmapfactory. options (); options. indither = false; options. inpreferredconfig = bitmap. config. argb_8888; cursor = CR. query (Uri, new string [] {mediastore. video. media. _ id}, null); If (cursor = NULL | cursor. getcount () = 0) {return NULL;} cursor. movetofirst (); string videoid = cursor. getstring (cursor. getcolumnindex (mediastore. video. media. _ id); // image ID in image table. sif (videoid = NULL) {return NULL;} cursor. close (); long videoidlong = long. parselong (videoid); bitmap = mediastore. video. thumbnails. getthumbnail (Cr, videoidlong, images. thumbnails. micro_kind, options); Return bitmap ;}
/**
* Obtain the specified video thumbnail Based on the video address path in the mobile phone.
* @ Param cr
* @ Param filename local video address
* @ Return returns bitmap data.
*/
Java code
- Public static bitmap getvideothumbnail (contentresolver Cr, Uri URI ){
- Bitmap bitmap = NULL;
- Bitmapfactory. Options = new bitmapfactory. Options ();
- Options. indither = false;
- Options. inpreferredconfig = bitmap. config. argb_8888;
- Cursor cursor = Cr. Query (Uri, new string [] {mediastore. Video. Media. _ id },
Null, null,
Null );
- If (cursor = NULL | cursor. getcount () =
0 ){
- Return NULL;
- }
- Cursor. movetofirst ();
- String videoid = cursor. getstring (cursor. getcolumnindex (mediastore. Video. Media. _ id ));
// Image ID in image table. s
- If (videoid = NULL ){
- Return NULL;
- }
- Cursor. Close ();
- Long videoidlong = long. parselong (videoid );
- Bitmap = mediastore. Video. thumbnails. getthumbnail (Cr, videoidlong, images. thumbnails. micro_kind, options );
- Return bitmap;
- }