国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 通過Intent調用系統拍照程序出現圖片太小的問題解決辦法

2019-12-12 02:27:40
字體:
來源:轉載
供稿:網友

Android 通過Intent調用系統拍照程序出現圖片太小的問題解決辦法

Intent it = newIntent("android.media.action.IMAGE_CAPTURE");startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);

按下拍照鍵后,會返回到你的activity,所以你的activity要在onActivityResult方法里加一個處理,

protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) {   super.onActivityResult(requestCode, resultCode, data);   try{     Bundle extras = data.getExtras();     Bitmap b = (Bitmap) extras.get("data");     take = b;     ImageView img = (ImageView)findViewById(R.id.image);     img.setImageBitmap(take);   }catch(Exception e){   } }

但是這樣你會發現這個bitmap尺寸太小了。明顯是被壓縮過了,要像返回未被壓縮的照片,那么你要給調用系統拍照程序intent加上參數,指定圖片輸出的位置。

Intent it = newIntent("android.media.action.IMAGE_CAPTURE");it.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(newFile(F.SD_CARD_TEMP_PHOTO_PATH)));startActivityForResult(it, Activity.DEFAULT_KEYS_DIALER);

這樣就是大圖片返回了。

protectedvoidonActivityResult(intrequestCode, intresultCode, Intent data) {   super.onActivityResult(requestCode, resultCode, data);   try{     ImageView img = (ImageView)findViewById(R.id.image);     take = U.ResizeBitmap(U.getBitmapForFile(F.SD_CARD_TEMP_PHOTO_PATH), 640);     img.setImageBitmap(take);     imgflag = true;   }catch(Exception e){    } }

另外注意一下,返回的那個bitmap會很大,你用完以后要把它回收掉,不然你很容易內存報oom錯誤

public static Bitmap ResizeBitmap(Bitmap bitmap, intnewWidth) {    intwidth = bitmap.getWidth();   intheight = bitmap.getHeight();   floattemp = ((float) height) / ((float) width);   intnewHeight = (int) ((newWidth) * temp);   floatscaleWidth = ((float) newWidth) / width;   floatscaleHeight = ((float) newHeight) / height;   Matrix matrix = newMatrix();   // resize the bit map   matrix.postScale(scaleWidth, scaleHeight);   // matrix.postRotate(45);   Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);   bitmap.recycle();   return resizedBitmap; }

以上就是Android 調用系統拍照出現問題的解決辦法,如有疑問大家請留言討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泰和县| 天峨县| 蓝山县| 海淀区| 弋阳县| 张掖市| 榆林市| 财经| 莱西市| 东阳市| 延川县| 怀来县| 平阴县| 东海县| 江西省| 竹溪县| 广河县| 高州市| 宁波市| 平安县| 鄂尔多斯市| 北海市| 阿拉善左旗| 河曲县| 黎川县| 修文县| 宝坻区| 治县。| 玛多县| 吐鲁番市| 沐川县| 楚雄市| 道孚县| 濮阳县| 南康市| 城口县| 庄河市| 阿尔山市| 柳州市| 华池县| 瓮安县|