android中 MediaStore提取缩略图和原始图像

提取图像的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);

在 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();

bitmap = MediaStore.Images.Media.getBitmap(resolver, originalUri );

} catch (IOException e) {

}

}

}

上一篇:git 不能创建分支


下一篇:世界最*邮件服务器组合Linux + PMTA + OEMPRO,PowerMTA 安装