码迷,mamicode.com
首页 > 其他好文 > 详细

解决相机拍照不清晰,拍照旋转问题!

时间:2014-12-17 12:16:12      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:android   ar   io   os   sp   for   on   art   问题   

private Uri uri;

//拍照

Intent getImageByCamera = new Intent("android.media.action.IMAGE_CAPTURE"); 

ContentValues values = new ContentValues();  
       values.put(MediaStore.Images.Media.DISPLAY_NAME, String.valueOf(System.currentTimeMillis())+".jpg");  
       values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");  
       uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
       getImageByCamera.putExtra(MediaStore.Images.Media.ORIENTATION, 0);  
       getImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, uri);

startActivityForResult(getImageByCamera,REQUEST_CAMERA);

//获取拍照的图片

if (requestCode == REQUEST_CAMERA) { //相机获取照片
String path = Tool.getPathFromUri(context, uri);
int orientation = Tool.readPictureDegree(path);//获取旋转角度
AppLog.d("dingdongkai", "orientation==="+orientation);
if(Math.abs(orientation) > 0){
Bitmap bit = getBitmapFromUri(uri);
   bitmap =  Tool.rotaingImageView(orientation, bit);//旋转图片  
}  
startPhotoZoom(Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, null,null)));

//根据uri获取图片路径

public static String getPathFromUri(Context mContext,Uri contentUri){
AppLog.d("dingdongkai", "contentUri==="+contentUri.toString());
   String[] proj = { MediaStore.Images.Media.DATA };
   CursorLoader loader = new CursorLoader(mContext, contentUri, proj, null, null, null);
   Cursor cursor = loader.loadInBackground();
   int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
   cursor.moveToFirst();
   return cursor.getString(column_index);
}

 

//获取图片的旋转角度
public static int readPictureDegree(String path) {  
int degree  = 0;  
try {
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;  
}  

 

/**
 * 裁剪图片方法实现
 * 
 * @param uri
 */
public void startPhotoZoom(Uri uri) {
// 设置裁剪属性
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 320);
intent.putExtra("outputY", 320);
intent.putExtra("return-data", true);
startActivityForResult(intent, 6);
}

解决相机拍照不清晰,拍照旋转问题!

标签:android   ar   io   os   sp   for   on   art   问题   

原文地址:http://www.cnblogs.com/xrtd/p/4168820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!