1

我来找你是因为我的定制相机有一个大问题:图像被拉伸了!我从维度上评价了这个问题,但我没有解决它。

如果您想要图片显示问题,我将发布它

这是我的代码:

public class CameraActivity extends Activity{

private SurfaceView surface_view;
private Camera mCamera;
SurfaceHolder.Callback sh_ob = null;
SurfaceHolder surface_holder        = null;
SurfaceHolder.Callback sh_callback  = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFormat(PixelFormat.TRANSLUCENT);

    surface_view = new SurfaceView(getApplicationContext());
    addContentView(surface_view, new WindowManager.LayoutParams(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT));

    if (surface_holder == null) {
        surface_holder = surface_view.getHolder();
    }

    sh_callback = my_callback();
    surface_holder.addCallback(sh_callback);
}

SurfaceHolder.Callback my_callback() {
    SurfaceHolder.Callback ob1 = new SurfaceHolder.Callback() {

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            mCamera.stopPreview();
            mCamera.release();
            mCamera = null;
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            mCamera = Camera.open();

            try {
                mCamera.setPreviewDisplay(holder);
            } catch (IOException exception) {
                mCamera.release();
                mCamera = null;
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            mCamera.startPreview();
        }
    };
    return ob1;
}

}

感谢您的帮助:D

4

1 回答 1

0

您不能在全屏上拉伸表面;您应该根据相机纵横比进行设置。要涵盖所有情况,您需要更多回调。在这里查看一个不错的包装类:http ://www.vogella.com/code/de.vogella.android.gallery/src/com/example/android/hcgallery/CameraFragment.html

于 2013-10-27T20:34:16.130 回答