旋转BMP并显示右侧
-
25-09-2019 - |
题
我有一个应用图片并在图像视图上显示图片的应用程序。问题是,我只能在景观模式下拍摄图片,以使BMP右侧显示 - 如果在肖像模式下拍摄图片,我可以将其旋转到右侧
谢谢!
这是我用来将图像放置在IMG视图中的代码 -
private void processCameraImage(Intent intent) {
setContentView(R.layout.detectlayout);
((Button) findViewById(R.id.detect_face)).setOnClickListener(btnClick);
ImageView imageView = (ImageView) findViewById(R.id.image_view);
cameraBitmap = (Bitmap) intent.getExtras().get("data");
imageView.setImageBitmap(cameraBitmap);
有一个检测到的按钮将检测到是否存在面孔。
解决方案
这就是您将旋转BMP的方式:
private Bitmap rotateImage(Bitmap b, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)b.Width/2,(float)b.Height / 2);
//rotate
g.RotateTransform(angle);
//move image back
g.TranslateTransform(-(float)b.Width/2,-(float)b.Height / 2);
}
其他提示
这是我在活动中使用onActivityResult()的代码。返回的意图是为了选择类型图像/*的图像。对我来说效果很好!
Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
不隶属于 StackOverflow