[英]Camera is stretching in portrait mode
我试图将相机放在Android手机上的纵向SurfaceView中。 我使用http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html将相机放入surfaceView。 然而,相机旋转90度,所以我尝试使用setDisplayOrientation(90)来修复它,但这会压缩图像(它可能没有正确调整SurfaceView的大小?)。 我该怎么做才能让相机不被挤压?
您需要根据旋转调整图像大小。 请看这里的例子。
如果您使用的是Android API演示,则需要修改OnLayout()
函数。
基本上是Android API演示,根据宽高比设置预览大小,以便预览图像被压缩并在纵向模式下以小尺寸显示在屏幕中心。
即使我们将屏幕方向设置为纵向模式,也不会更改预览宽度和高度。 这就是预览图像被压扁的原因。
唯一对我有用的是
在代码mCamera.setDisplayOrientation(90);
布局的height
和width
都有fill_parent
。
而清单文件有android:screenOrientation="portrait"
使用此功能调整大小图像对您有用
public Bitmap resize(Bitmap img,int Width,int Height){
int width = img.getWidth();
int height = img.getHeight();
int newWidth = (int) Width;
int newHeight = (int) Height;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
//matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(img, 0, 0, width, height, matrix, true);
return resizedBitmap;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.