如何获得图像的旋转的程度 [英] How to get degree of rotation of image
本文介绍了如何获得图像的旋转的程度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到从图库中的形象和在ImageView的显示。有时,图像显示90度逆时针。
I'm getting an image from gallery and display it in an imageView. Sometimes, image displays 90 degrees CCW.
所以,我的问题是:
1-是有可能得到的图像的旋转角θ
2 - 是否有可能通过人脸检测库获得角?如果是的话,你认为哪个库?
So, my question is: 1- is it possible to get angle of rotation of image? 2- is it possible to get angle by a face detection library? if yes, which library you suggest?
任何建议将AP preciated。谢谢你。
any recommendation would be appreciated. Thanks.
推荐答案
好吧,我发现我与你分享的解决方案。
Okay, I found a solution that I share it with you.
public class ImageCorrection extends Activity {
private final static String TAG = MainActivity.class.getSimpleName();
private final static int RESULT_LOAD_IMAGE = 100;
private ImageButton imageButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_face_detection);
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_LOAD_IMAGE:
if (data != null) {
Uri imageUri = data.getData();
Log.d(TAG, "Image Uri: " + imageUri.toString());
try {
Bitmap myImg = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
if(myImg == null) {
Log.e(TAG, "Image bitmap is null...");
return;
}
Cursor cur;
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
if(Build.VERSION.SDK_INT < 11)
cur = managedQuery(imageUri, orientationColumn, null, null, null);
else
cur = getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
Log.d(TAG, "Image Orientation: " + orientation);
}
Matrix matrix = new Matrix();
matrix.reset();
matrix.postRotate(orientation);
Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(), matrix, true);
imageButton.setImageBitmap(rotated);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
default:
break;
}
}
}
这篇关于如何获得图像的旋转的程度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文