android 中用Intent提取缩略图和原始图像
2010-05-31 14:51:00 来源:WEB开发网提取图像的Thumbnail
1)
启动Intent
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKED);
在 onActivityResult 中
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
Bitmap bitmap = null;
ContentResolver resolver = getContentResolver();
if (requestCode == REQUEST_CODE_PHOTO_PICKED) {
final Bundle extras = data.getExtras();
if (extras != null)
bitmap = extras.getParcelable("data");
}
}
经过阅读android源代码发现,此方法返回的data 必须小于100k
2)
启动Intent
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKED);
在 onActivityResult 中
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
Bitmap bitmap = null;
ContentResolver resolver = getContentResolver();
if (requestCode == REQUEST_CODE_PHOTO_PICKED) {
try {
Uri originalUri = data.getData();
Uri thumb = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, originalUri.getLastPathSegment());
bitmap = MediaStore.Images.Media.getBitmap(resolver, thumb);
} catch (IOException e) {
}
}
}
提取图像原数据
启动Intent
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_CODE_PHOTO_PICKED);
更多精彩
赞助商链接