android實現視頻圖片取縮圖

來源:互聯網
上載者:User

標籤:

取縮圖不等同於縮放圖片.

縮放圖片是保持不失真的情況下縮放處理,並進行平滑處理.

縮圖則不然,允許失真,目的只是取出圖片的輪廓.

儲存Bitmap圖片

private  void saveBitmap(Bitmap bm,String picName) {Log.e(TAG, "儲存圖片");String icon_dir=mMedialist.get(mMedialist.size()-1).getIconpath().replace("/", "__");//  String icon_dir=picName.replace("/", "__");File dir = new File(Environment.getExternalStorageDirectory().toString()+"/movdo/clip",icon_dir );if(!dir.exists())if(!dir.mkdir())Log.e(TAG, "don‘t create dir");elseLog.i(TAG, "DIR is created");picName=picName.replace(".mp4", ".jpg");File f = new File(dir.getAbsolutePath(), "0.jpg");if (f.exists()) {f.delete();}try {FileOutputStream out = new FileOutputStream(f);bm.compress(Bitmap.CompressFormat.PNG, 90, out);out.flush();out.close();Log.i(TAG, "已經儲存");} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}

為圖片取縮圖

public Bitmap getImageThumbnail(String filename,Bitmap bmp,int width,int height) {Bitmap bitmap=ThumbnailUtils.extractThumbnail(bmp, 300, 300);   saveBitmap(bitmap,filename);return bitmap;  }

 為視頻取縮圖

private Bitmap getVideoThumbnail(String videoPath, int width , int height){Bitmap bitmap = null;bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, Thumbnails.MINI_KIND);bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);String filename=new String();saveBitmap(bitmap,mMedialist.get(mMedialist.size()-1).getItemname());return bitmap;}

 根據路徑解析進Bitmap

Bitmap thumb = BitmapFactory.decodeFile(filepath);getImageThumbnail(filename,thumb,300,300);

 

android實現視頻圖片取縮圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.