Android 打开相机获得路径:注意三星手机图片方向问题。
来源:互联网 发布:java密码加密方式 编辑:程序博客网 时间:2024/04/30 10:38
因为使用的imageloader加载图片:防止oom,可以进行二级缓存,不用担心我们的内存,所以获取的是图片的地址。
打开系统相册简单:传参的时候有传:文件路径:返回的data就是空的,但是full图片(也就是原始的图片:区别于缩略图)会在文件路径生成的;
如果没传文件路径:返回的就是缩略图。
注意:三星手机的图片问题
详细代码:内存控制和文件存放调整完的最终版本
//获取原始图片的角度
private int getBitmapDegree(String path) {
int degree = 0;
try {
// 从指定路径下读取图片,并获取其EXIF信息
ExifInterface exifInterface = new ExifInterface(path);
// 获取图片的旋转信息
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
Log.e(“jxf”,”orientation”+orientation);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
/** * 获取磁盘缓存路径 * @param name 文件夹名称 * @return 缓存路径 */private File getDiskCacheDir(Context context, String name) { if (Environment.MEDIA_MOUNTED.equals(Environment .getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { File file = new File(context.getExternalCacheDir(), name); if (!file.exists()) file.mkdirs(); return file; } else { File file = new File(context.getCacheDir(), name); if (!file.exists()) file.mkdirs(); return file; }}/** * 保存图片到系统相册 * @param image */private Uri saveImageToDICM(Context context, File image) { Uri uri = null; // 保存到相册 try { String uriString = MediaStore.Images.Media.insertImage( context.getContentResolver(), image.getAbsolutePath(), image.getName(), image.getName()); uri = Uri.parse(uriString);
// // 通知系统相册刷新
// context.sendBroadcast(new Intent(
// Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(image)));
} catch (FileNotFoundException e) {
Log.e(“jxf”,”捕捉异常FileNotFoundException”);
} return uri;} /**开启相机*/ case R.id.btn_take_photo: //防止内存溢出 Log.e("jxf", "ImageLoader清理内存缓存"); ImageLoader.getInstance().clearMemoryCache(); Intent intent5 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent5.putExtra(MediaStore.EXTRA_OUTPUT, getOutputPhoto()); startActivityForResult(intent5, REQUEST_CODE_IMAGE_CAPTURE); menuWindow.dismiss();//照相返回的
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) { /**拍照*/ case REQUEST_CODE_IMAGE_CAPTURE: if (resultCode == RESULT_OK) {
// uri =saveImageToDICM(getApplicationContext(),
// outPutPhoto);
// if (uri == null) {
// return;
// }
// Log.e(“jxf”,”打印保存照片地址uri”+uri.toString());
Log.e(“jxf”,”打印保存照片地址path”+outPutPhoto.getAbsolutePath());
int degree=getBitmapDegree(outPutPhoto.getAbsolutePath());
Log.e(“jxf”,”打印旋转尺寸”+degree);
//使用大图做尺寸压缩
BitmapFactory.Options options = new BitmapFactory.Options();
// // 从解码器中获取原始图片的宽高,这样避免了直接申请内存空间
// options.inJustDecodeBounds = true;
// Calculate inSampleSize
options.inSampleSize = 5;
// // 压缩完后便可以将inJustDecodeBounds设置为false了。
// options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
//做尺寸压缩
Log.e(“jxf”,”做尺寸压缩”);
Bitmap bitmap = BitmapFactory.decodeFile(outPutPhoto.getAbsolutePath(), options);
Log.e(“jxf”,”bitmap大小打印”+(bitmap.getRowBytes() * bitmap.getHeight()));
// 根据旋转角度,生成旋转矩阵
Matrix matrix = new Matrix();
matrix.postRotate(degree);
Log.e(“jxf”, “做角度变换了”);
Bitmap returnBm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Log.e(“jxf”,”returnBm大小打印”+(returnBm.getRowBytes() * returnBm.getHeight()));
//压缩进原来的文件中
File imagePath = new File(getCacheDir(), “” + Calendar.getInstance().getTimeInMillis());// /sdcard/aijingxi/cropImage
File parentFile = imagePath.getParentFile();
if (!parentFile.exists()) {// 判断上级目录是否存在,不存在就需要创建
parentFile.mkdirs();
}
// 把Bitmap对象持久化到本地
OutputStream os = null;
try {
os = new FileOutputStream(imagePath);
returnBm.compress(Bitmap.CompressFormat.JPEG, 100, os);
Log.e(“jxf”, “做质量压缩压缩进硬盘”);
os.flush();
os.close();
} catch (FileNotFoundException e) {
Log.e(“jxf”,”切图类1–bitmap图片压缩时,报FileNotFoundException异常”);
e.printStackTrace();
} catch (IOException e) {
Log.e(“jxf”,”切图类1–bitmap图片压缩时,报IOException异常”);
e.printStackTrace();
}
//释放
if (bitmap != null && !bitmap.isRecycled()) {
// 回收并且置为null
bitmap.recycle();
bitmap = null;
Log.e(“jxf”, “bitmap回收”);
}
System.gc();
//释放
if (returnBm != null && !returnBm.isRecycled()) {
// 回收并且置为null
returnBm.recycle();
returnBm = null;
Log.e(“jxf”, “returnBm回收”);
}
System.gc();
uri =saveImageToDICM(getApplicationContext(),
imagePath);
Intent intent = new Intent(this, CropActivity.class);
intent.putExtra(“uri”, uri.toString());
Log.e(“jxf”,”传递的uri==”+ uri.toString());
startActivityForResult(intent, CROP_REQUEST_CODE);
}
break;
有管照相机的一些网站:有自己写caream的、有打开系统的
http://blog.csdn.net/dinglin_87/article/details/7917473 (重点)
http://cowboy.1988.blog.163.com/blog/static/75105798201422645818776/
http://www.cnblogs.com/franksunny/archive/2011/11/17/2252926.html
http://blog.csdn.net/jianghuiquan/article/details/8569187 (好文)
- Android 打开相机获得路径:注意三星手机图片方向问题。
- android调用系统相机的方法,并且解决三星手机遇到的问题,图片旋转、压缩
- Android解决三星手机图片旋转问题
- 关于三星手机调用系统相机拍照旋转屏导致图片数据丢失问题
- Android拍照和从相册获取图片(解决android7.0打开相机崩溃的问题),同时也解决了拍完照后图片方向不正的问题
- Android开发——相册拍照_03.解决相机拍照之后部分手机无法将图片保存到路径或部分手机点击相机确定无法返回问题
- android解决三星手机拍照获取图片的问题
- 打开文件夹获得图片路径
- android调用系统相机的方法,并且解决三星手机遇到的问题
- Android 自定义前置相机(三星手机拍照时照片旋转90度问题)
- <android>头像上传,打开相册 —— 图片压缩——上传成功 (附三星手机适配图片旋转问题)
- 三星手机调用系统相机问题整理及解决方案
- 三星手机选择图片旋转问题
- Android手机图片路径
- Android 三星手机拍照图片旋转处理
- Android 从手机相册获取图片 uri 路径 从相机获取照片
- Android打开系统相机、相册,并进行裁剪图片的工具类CameraUtil,以及相册获取图片注意要点。
- Android 调用相机、打开相册、裁剪图片
- 麻省理工-线性代数 第一课
- 蓝桥杯 趣味算式
- eclipse 生成javadoc乱码问题解决
- How can I patch the kernel in Yocto Project
- iOS runtime 运行时( 三 深谈)
- Android 打开相机获得路径:注意三星手机图片方向问题。
- MySql 5.6异常处理: Row size too large (> 8126)
- 关于 U盘插入linux时系统时没有反应
- UNIX域套接字轮询XSI消息队列
- 安卓开发小知识-AppWidget入门
- PLC远程通讯功能集锦(互联网、局域网)(PLC远程监控,PLC远程监视,PLC手机监控)
- javascript或jquery实现延迟加载js文件
- C++中this指针的用法及介绍
- php中JSON的标准:双引号而非单引号