如何在一个平方的SurfaceView(如Instagram)中将相机预览大小设置为平方宽高比 [英] How can I set camera preview size to squared aspect ratio in a squared SurfaceView (like Instagram)

查看:413
本文介绍了如何在一个平方的SurfaceView(如Instagram)中将相机预览大小设置为平方宽高比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发自己的相机活动,但我有一个问题,我不能解决...

I'm trying to develop my own camera activity, but I have a problem that I'm not unable to solve...

我想要的是这非常类似于instagram相框,这是我得到:

What I want, is something very similiar to instagram photo frame, and this is what I get:

当我得到这样的东西时:

When I should get something like this:

和...

当我应该得到像:

我想我正在管理SurfaceView和相机预览,只使用

I think I'm maanaging the SurfaceView and Camera preview well, only using

Camera.Parameters parameters = camera.getParameters();
camera.setDisplayOrientation(90);

和自定义SurfaceView:

and Custom SurfaceView:

public class SquaredSurfaceView extends SurfaceView {

private int width;
private int height;

public SquaredSurfaceView(Context context) {
    super(context);
}

public SquaredSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public SquaredSurfaceView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    width = MeasureSpec.getSize(widthMeasureSpec);
    height = width;
    setMeasuredDimension(width, width);
}

public int getViewWidth() {
    return width;
}

public int getViewHeight() {
    return height;
}

}

我做错了什么? : - (

What I'm doing wrong?? :-(

推荐答案

如前所述,您需要找到正确的预览大小(纵横比为1:1)可能你必须使用FrameLayout的SurfacePreview。似乎你有和宽高比问题,也许你有正确的预览大小,但你把它放在一个不正确的布局。

As said before you need to find the correct preview size (the one with aspect ratio 1:1) and probably you have to use FrameLayout for the SurfacePreview. It seems that you have and aspect ratio problem maybe you have the right preview size but you are placing it in an incorrect layout.

另一个解决方案可能是(就像Instagram的),使你的相机的全尺寸,然后隐藏一些地方的外衣只是为了使它看起来像一个正方形然后通过软件,你必须剪切图像,使其成为一个真正的方格。

Another solution might be (just like Instagram does) to make your camera at full size and then hide some areas of the layour just to make it look like a square. Then by software you would have to cut the image to make it a real square.

希望这有助于您

这篇关于如何在一个平方的SurfaceView(如Instagram)中将相机预览大小设置为平方宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆