標籤:
取縮圖不等同於縮放圖片.
縮放圖片是保持不失真的情況下縮放處理,並進行平滑處理.
縮圖則不然,允許失真,目的只是取出圖片的輪廓.
儲存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實現視頻圖片取縮圖