Get*_*ame 24 camera android rotation
我正在编写一个使用相机的Android应用程序.我将相机显示方向设置为90,我的活动是纵向:
camera.setDisplayOrientation(90);
Run Code Online (Sandbox Code Playgroud)
我得到一个很好的预览图片,但生成的图像旋转到-90度(逆时针)和
exif.getAttribute(ExifInterface.TAG_ORIENTATION)
Run Code Online (Sandbox Code Playgroud)
返回ORIENTATION_NORMAL
是否是预期的行为?我应该在捕获后旋转结果图像吗?
设备 - Nexus S,API - 10
Ame*_*eer 23
试试这个
try {
File f = new File(imagePath);
ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int angle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
angle = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
angle = 180;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
angle = 270;
}
Matrix mat = new Matrix();
mat.postRotate(angle);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(f),
null, options);
bitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), mat, true);
ByteArrayOutputStream outstudentstreamOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100,
outstudentstreamOutputStream);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
Log.w("TAG", "-- Error in setting image");
} catch (OutOfMemoryError oom) {
Log.w("TAG", "-- OOM Error in setting image");
}
Run Code Online (Sandbox Code Playgroud)
它会工作
小智 14
问题是相机方向是一个彻底的灾难(如捕获图像),因为OEM不遵守标准.HTC手机以一种方式做事,三星手机以不同的方式做事,Nexus系列似乎坚持无论哪家供应商,基于CM7的ROM我认为无论哪种硬件都遵循标准,但你明白了.你必须根据手机/ ROM确定要做什么.请参阅此处的讨论:Android相机在某些设备上捕获无法解释的旋转(不在EXIF中)
小智 6
我遇到了和你一样的问题,但我已经解决了.
你应该使用相同的代码:
Camera.Parameters parameters = camera.getParameters();
parameters.setRotation(90);
camera.setParameters(parameters);
Run Code Online (Sandbox Code Playgroud)
我希望你也可以使用这个代码.
| 归档时间: |
|
| 查看次数: |
36559 次 |
| 最近记录: |