android中 MediaStore提取缩略图和原始图像
android中 MediaStore提取縮略圖和原始圖像?.
歡迎轉(zhuǎn)載:http://blog.csdn.net/djy1992/article/details/10005767提取圖像的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");
??????????? }
??????? }
??????? 經(jīng)過閱讀android源代碼發(fā)現(xiàn),此方法返回的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) {
??????? }
??????????? }
??????? }
提取圖像原數(shù)據(jù)
??????? 啟動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) {
??????? }
??????????? }
??????? }
轉(zhuǎn)載于:https://www.cnblogs.com/wuwa/p/6191583.html
總結(jié)
以上是生活随笔為你收集整理的android中 MediaStore提取缩略图和原始图像的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到别人卖棺材是什么意思
- 下一篇: JTable 失去焦点时取消编辑状态