相机在竖屏模式下拉伸

6
4个回答

6

根据旋转角度调整图像大小。可以参考这里的示例。


在这个例子中,高度和宽度应该是多少?我希望预览大约占屏幕的一半,但我不想硬编码数值,以便它可以适用于不同大小的屏幕。 - user1154920
这是SurfaceHolder回调方法,所以该方法的高度和宽度参数将由硬件设置。如果您想要预览画面为屏幕的一半大小,则可以在“if”语句中设置它们,例如:parameters.setPreviewSize(width/2, height/2)。 - John J Smith

2
如果您正在使用Android API演示文稿,则需要修改OnLayout()函数。
基本上,Android API演示设置预览大小,根据纵横比,使预览图像在纵向模式下居中显示,并具有小的尺寸。
即使我们将屏幕方向设置为纵向模式,预览宽度和高度也不会改变。这就是为什么预览图像被压缩的原因。

0

对我有效的唯一方法是

在代码中使用 mCamera.setDisplayOrientation(90);

布局中 heightwidth 都设置为 fill_parent

清单文件中设置了 android:screenOrientation="portrait"


-2

使用此函数调整图像大小,对您会很有用

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;

} 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接