WEB开发网
开发学院手机开发Android 开发 android 中用Intent提取缩略图和原始图像 阅读

android 中用Intent提取缩略图和原始图像

 2010-05-31 14:51:00 来源:WEB开发网   
核心提示:提取图像的Thumbnail1)启动IntentIntent intent = new Intent(Intent.ACTION_GET_CONTENT, null);intent.setType("image/*");intent.putExtra("return-data",

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

1 2  下一页

Tags:android 中用 Intent

编辑录入:coldstar [复制链接] [打 印]
赞助商链接