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

首頁 > 系統(tǒng) > Android > 正文

Android 通過Intent調(diào)用系統(tǒng)拍照程序出現(xiàn)圖片太小的問題解決辦法

2019-10-22 18:32:10
字體:
供稿:網(wǎng)友

Android 通過Intent調(diào)用系統(tǒng)拍照程序出現(xiàn)圖片太小的問題解決辦法

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){   } }

但是這樣你會發(fā)現(xiàn)這個bitmap尺寸太小了。明顯是被壓縮過了,要像返回未被壓縮的照片,那么你要給調(diào)用系統(tǒng)拍照程序intent加上參數(shù),指定圖片輸出的位置。

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會很大,你用完以后要把它回收掉,不然你很容易內(nèi)存報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 調(diào)用系統(tǒng)拍照出現(xiàn)問題的解決辦法,如有疑問大家請留言討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 喜德县| 龙山县| 建德市| 固阳县| 远安县| 江西省| 泰宁县| 晋宁县| 沽源县| 长治市| 建德市| 于都县| 靖安县| 长丰县| 永安市| 沁水县| 武功县| 广水市| 怀宁县| 峨眉山市| 古浪县| 定结县| 中阳县| 宜春市| 江门市| 临潭县| 奈曼旗| 大宁县| 江孜县| 吴川市| 普宁市| 南澳县| 吴忠市| 张掖市| 郴州市| 灵寿县| 长沙县| 宝兴县| 融水| 多伦县| 郁南县|