Android 打开系统图库实现方法
来源:互联网 发布:上传歌曲到网络qq音乐 编辑:程序博客网 时间:2024/05/22 13:31
1.打开系统图库
Intent intent = new Intent(Intent.ACTION_PICK);//选择intent.setType("image/*");//选择图片startActivityForResult(intent, PICK_CODE);
2.在onActivityResult()方法中获得图片
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICK_CODE){ if (data != null){ Uri uri = data.getData(); Cursor cursor = getContentResolver().query(uri, null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); mCurrentPhotoStr = cursor.getString(idx); cursor.close(); resizePhoto(); mPhoto.setImageBitmap(mPhotoIma); mTip.setText("Click Dectect ==>"); } } super.onActivityResult(requestCode, resultCode, data); }
3.压缩图片
/** * 压缩照片--每张图片不能超过3M */ private void resizePhoto() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoStr,options); double ratio = Math.max(options.outWidth*1.0d/1024,options.outHeight*1.0d/1024); options.inSampleSize = (int) Math.ceil(ratio); options.inJustDecodeBounds = false; mPhotoIma = BitmapFactory.decodeFile(mCurrentPhotoStr, options); }
阅读全文
0 0
- Android 打开系统图库实现方法
- android 打开系统图库的方法
- android打开系统图库终极适配
- 打开系统图库
- Android 保存图片到系统图库 -- 利用 “系统保存屏幕截图” 的方法实现
- android 调用系统图库打开指定路径的图片
- Android启动系统相机,打开图库选择图片
- Android 刷新系统图库
- android 调用系统照相机和图库的方法
- 关于主动刷新Android系统图库方法总结
- Android如何将图片存入到系统图库的方法
- IOS 获取系统图库与打开拍照
- android的系统图库在
- ContentResolver访问android系统图库
- 打开图库
- Android中使用Intent打开本地图库
- Android从系统图库拿到文件--重命名--通知图库更新
- 应用进入系统图库(Gallery)方法
- 插件介绍:bootstrap 左右移动多选框插件~Multiselect
- 学习LInux命令(17)
- RSA 算法
- java基础(二)
- 创建spdier的模板
- Android 打开系统图库实现方法
- 基于jquery,bootstrap数据验证插件bootstrapValidator 教程
- 搜索框智能提示小Demo
- Kali渗透测试——TLSSLed
- LeetCode26. Remove Duplicates from Sorted Array
- 网上搜寻资料的能力严重不足,有何实用经验和方法?
- Jmeter 3.2 及插件的安装和配置
- 利用OpenMP加速拉伸图像操作
- 小动画:一个圆循环变大再透明