选择本地图片并转化成bitmap

来源:互联网 发布:smartsvn linux 破解 编辑:程序博客网 时间:2024/05/16 03:57
Intent intent=new Intent();intent.type("image/*");intent.setAction(Intent.ACTION_GET_CONTENT);starActivityForResult(intent,1);@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);if (resultCode == RESULT_OK) {try {             Uri uri = data.getData();             bitmap = null;             ContentResolver resolver = getContentResolver();             bitmap = BitmapFactory.decodeStream(resolver.openInputStream(uri));             int width = bitmap.getWidth();             int height = bitmap.getHeight();             float scal = 100 / (float) width;if (width >= 100) {             Matrix matrix = new Matrix();             matrix.postScale(scal, scal);             pickBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,height, matrix, true);             bitmap.recycle();// 回收Bitmap的空间} else {             bitmap = pickBitmap;}            image_photo.setImageBitmap(pickBitmap);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
0 0
原创粉丝点击