嗨,已经建立在摄像机预览上了。
当然,它甚至在肖像模式下也会显示景观预览。我用一些额外的代码改变了这个。然而,无论你的风景/肖像,它总是保存在景观模式的图像。
我现在也把它强制到了肖像模式:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);基本上我拍摄的任何图像都是在风景中出现的。(旋转所拍摄的图像).
我如何使它保存在定向模式的照片,或锁定到肖像假设?
我已经考虑过拍摄照片阵列和旋转90度。但这将需要将图像绘制到位图,旋转,然后存储回数组。杀得太多了?除非你能直接旋转图像数组?
发布于 2012-05-15 12:59:59
首先,使用下面的代码段检查摄像机的方向:
private int lookupRotation() {
WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
int rotation = mDisplay.getRotation();
Log.v(LOG_TAG, "rotation: " + rotation);
return rotation;
}然后检查您想要的旋转,使用并设置您的方向:
if (rotation == Surface.ROTATION_0) {
int degreesRotate = 90;
}使用以下代码段调整位图的大小,并根据方向旋转位图:
private Bitmap createBitmap(byte[] imageData, int maxWidth, int maxHeight,
int rotationDegrees) throws FileNotFoundException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inDensity = 240;
int imageWidth = 0;
int imageHeight = 0;
Bitmap image = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length, options);
imageWidth = image.getWidth();
imageHeight = image.getHeight();
if (imageWidth > maxWidth || imageHeight > maxHeight) {
double imageAspect = (double) imageWidth / imageHeight;
double desiredAspect = (double) maxWidth / maxHeight;
double scaleFactor;
if (imageAspect < desiredAspect) {
scaleFactor = (double) maxHeight / imageHeight;
} else {
scaleFactor = (double) maxWidth / imageWidth;
}
float scaleWidth = ((float) scaleFactor) * imageWidth;
float scaleHeight = ((float) scaleFactor) * imageHeight;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(image,
(int) scaleWidth, (int) scaleHeight, true);
image = scaledBitmap;
}
if (rotationDegrees != 0) {
int w = image.getWidth();
int h = image.getHeight();
mtx.postRotate(rotationDegrees);
Bitmap rotatedBMP = Bitmap.createBitmap(image, 0, 0, w, h, mtx,
true);
image = rotatedBMP;
}
return image;
}以上方法将根据方向返回位图。
https://stackoverflow.com/questions/10599639
复制相似问题