1、拍照
String name = DateFormat.format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg"; File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera"); if (!file.exists()) { file.mkdirs(); currentCameraPhotoFile = new File(file,name); if (!currentCameraPhotoFile.exists()) { currentCameraPhotoFile.createNewFile(); } } Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(currentCameraPhotoFile)); startActivityForResult(intent, CAMERA_WITH_DATA);
2、在onActivityResult里处理返回结果,
case CAMERA_WITH_DATA: {// 拍照 System.out.println("拍照返回。。。。。。。。。。。。。。。fileName"+currentCameraPhotoFile.getName()); if (null!= currentCameraPhotoFile) { Bitmap cameraImageBitmap = BitmapUtil.getBitmapFromBigFile(currentCameraPhotoFile.getPath(), measuredWidth, measuredHeight); rl_jobnewbackground.setBackground(new BitmapDrawable(getResources(), cameraImageBitmap)); } break;
3、处理大图OOM和部分手机拍照结果旋转问题,直接上代码吧
/** * 获取大图bitmap * @param path * @param width * @param height * @return */ public static Bitmap getBitmapFromBigFile(String path, int width, int height) { //校正旋转角度 Matrix matrix = new Matrix(); matrix.postRotate(getBitmapDegree(path)); // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // BitmapFactory.decodeResource(res, resId, options); BitmapFactory.decodeFile(path, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, width, height); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Bitmap decodeFile = BitmapFactory.decodeFile(path, options); decodeFile = Bitmap.createBitmap(decodeFile, 0, 0, decodeFile.getWidth(), decodeFile.getHeight(), matrix, true); return decodeFile; } /** * 读取图片的旋转的角度 * * @param path * 图片绝对路径 * @return 图片的旋转角度 */ public static int getBitmapDegree(String path) { int degree = 0; try { // 从指定路径下读取图片,并获取其EXIF信息 ExifInterface exifInterface = new ExifInterface(path); // 获取图片的旋转信息 int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 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; } /** * 计算出合理的inSampleSize * @param options * @param reqWidth * @param reqHeight * @return */ public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { final int halfHeight = height / 2; final int halfWidth = width / 2; // Calculate the largest inSampleSize value that is a power of 2 and // keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) { inSampleSize *= 2; } } return inSampleSize; }
相关推荐
你说你没事旋转照片干啥,实在是猜不透其居心何在,纯粹是在给开发者制造麻烦啊! 解决办法是获取到拍照后照片被旋转的角度,再旋转回去就好了。 具体思路: 1、首先在调用拍照方法时,保存拍照后的相片原图,得到...
看到网上有很多解决关于拍照后图片旋转的问题,特别是三星的机型问题最大,但是都不能很好的解决问题,所以花时间研究了下,终于解决了拍照后图片旋转的问题,再此把代码贴出来跟大家一起研究下,有什么不对的地方还...
android 解决部分手机拍照旋转问题
android 图片 拍照 删除 添加 旋转 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout....
该项目包括调用系统相机拍照,和从系统选取图片,并对图片进行裁剪(仿微信做法),并解决三星手机拍照和选取照片角度旋转问题
原文:http://blog.csdn.net/u012964281/article/details/41143169
Android调用系统相机拍照、实现压缩、图片旋转、保存以及6.0以上适配问题
主要介绍了Android 开发手机(三星)拍照应用照片旋转问题解决办法的相关资料,需要的朋友可以参考下
android相机拍照,存储 调用相册, 图片旋转,裁剪
Android调用相机拍照需要处理的权限获取和旋转问题
拍照或者从相册中选择图片后,我们都可以直接或间接的得到Uri或...大多数情况下操作图片不可避免的涉及到直接操作Bitmap,所以就需要解决图片旋转问题了,下面是演示如何拍照、选择相册中的图片后进行Bitmap旋转。
Android 拍照 或者选择相册图片,并剪切图片后,设置头像,解决三星手机拍照后图片旋转和图片过大时剪切失败的问题
三星手机自己为是的做了一个很酷的功能 - 拍照后自动旋转的功能,从而导致了需要回调的Activity被重新onCreate,使开发者在onActivityResult中得到 resultCode == RESULT_OK, 而 url == null 的现象。 此DEMO就是...
仿华为相机旋转动画,配置界面支持 随重力360度旋转
Android调用系统 拍照 相册 适配所有版本 7.0 恢复自动旋转
android自定义拍照,实现旋转90度以及高像素拍照,直接添加依赖包就可以使用了,也可以自己抽离出来添加进自己的项目
早几天在开放中遇到三星照相旋转90度,上网去找资源都没有完整的资源。之后自己尝试多种方法实现了。希望能帮助到大家
系统:Android 5.1 同时也适用Android 7.1 3288板子竖屏时,相机拉伸很严重 下面实现了摄像头90 度旋转,旋转角度只需修改 orientation。 diff --git a/hardware/rockchip/camera/CameraHal/CameraHal_Module.cpp ...