Android get picture or video thumbnail

Source: Internet
Author: User

    /*** Get thumbnails based on the specified image path and size This method has two advantages: 1. * Using a smaller memory space, the first fetch of the bitmap is actually null, just to read the width and height, * The second read bitmap is based on the proportional compressed image, the third read bitmap is the desired thumbnail.     2. * Thumbnails are not stretched for the original image, using the new 2.2 version of the tool thumbnailutils, the image generated using this tool will not be stretched. *      * @paramImagePath * Path to image *@paramWidth * Specifies the breadth of the output image *@paramHeight * Specifies the altitude of the output image *@returngenerated thumbnails*/     Public StaticBitmap Getimagethumbnail (String ImagePath,intWidthintheight) {Bitmap Bitmap=NULL; Bitmapfactory.options Options=Newbitmapfactory.options (); Options.injustdecodebounds=true; //get the width and height of this picture, note that the bitmap here is nullBitmap =bitmapfactory.decodefile (ImagePath, Options); Options.injustdecodebounds=false;//set to False//Calculating the zoom ratio    inth =Options.outheight; intW =Options.outwidth; intBewidth = w/width; intBeheight = h/height; intbe = 1; if(Bewidth <beheight) { be=Bewidth; }    Else{ be=Beheight; }    if(Be <= 0) { be= 1; } options.insamplesize=Be ; //re-read the picture, read the scaled bitmap, and note this time to set the Options.injustdecodebounds to FalseBitmap =bitmapfactory.decodefile (ImagePath, Options); //use Thumbnailutils to create thumbnails, where you want to specify which bitmap object to scaleBitmap =thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input); returnbitmap; }    /*** Get thumbnail images of videos first create a thumbnail of a video with Thumbnailutils, and then use thumbnailutils to generate a thumbnail of the specified size.     * If the desired thumbnail width and height are less than micro_kind, then the type will use Micro_kind as the KIND value, which saves memory. *      * @paramVideopath * Path to video *@paramWidth * Specifies the output video thumbnail size *@paramHeight * Specifies the altitude of the output video thumbnail *@paramKind * Refer to constants Mini_kind and Micro_kind in the MediaStore.Images.Thumbnails class. * of which, mini_kind:512 x 384,micro_kind:96 x *@returnSpecify the size of the video thumbnail*/     Public StaticBitmap Getvideothumbnail (String Videopath,intWidthintheight,intkind) {Bitmap Bitmap=NULL; //get thumbnail images of a videoBitmap =Thumbnailutils.createvideothumbnail (Videopath, kind); System.out.println ("W" +bitmap.getwidth ()); System.out.println ("H" +bitmap.getheight ()); Bitmap=thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input); returnbitmap; }

Android get picture or video thumbnail

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.