Intent intent=new Intent();
intent.type("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
starActivityForResult(intent,1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.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 block
e.printStackTrace();
}
}
}