android自定义相机拉伸surfaceview

概述我正面临相机视图的问题,即相机的视图正在拉伸,并没有提供像默认相机应用程序或任何其他相机应用程序给出的普通视图. 我无法获得相机用于拉伸大于屏幕尺寸的表面视图. enter code here private class SurfaceCallback implements SurfaceHolder.Callback { @Override public void surfa 我正面临相机视图的问题,即相机的视图正在拉伸,并没有提供像默认相机应用程序或任何其他相机应用程序给出的普通视图.
我无法获得相机用于拉伸大于屏幕尺寸的表面视图.

enter code here  private class SurfaceCallback implements SurfaceHolder.Callback {    @OverrIDe    public voID surfaceCreated(SurfaceHolder holder) {        try {            camera = Camera.open();             camera.setPrevIEwdisplay(holder);             camera.setdisplayOrIEntation(getPrevIEwDegree(MainActivity.this));            camera.startPrevIEw(); //         } catch (Exception e) {            e.printstacktrace();        }    }     @OverrIDe    public voID surfaceChanged(SurfaceHolder holder,int format,int wIDth,int height) {        setCameraParameters();    }    @OverrIDe    public voID surfaceDestroyed(SurfaceHolder holder) {    }}  private int getPrevIEwDegree(Activity activity) {    int rotation = activity.getwindowManager().getDefaultdisplay()            .getRotation();    int degree = 0;    switch (rotation) {        case Surface.ROTATION_0:            degree = 90;            break;        case Surface.ROTATION_90:            degree = 0;            break;        case Surface.ROTATION_180:            degree = 270;            break;        case Surface.ROTATION_270:            degree = 180;            break;    }    return degree;}private voID setCameraParameters() {    Camera.Parameters parameters = camera.getParameters();    List<Camera.Size> sizeList = parameters.getSupportedPrevIEwSizes();    if (sizeList.size() > 0) {        Camera.Size cameraSize = sizeList.get(0);        parameters.setPrevIEwSize(cameraSize.wIDth,cameraSize.height);    }    sizeList = parameters.getSupportedPictureSizes();    if (sizeList.size() > 0) {        Camera.Size cameraSize = sizeList.get(0);        for (Camera.Size size : sizeList) {            if (size.wIDth * size.height < 10 * 100) {                cameraSize = size;                break;            }        }        parameters.setPictureSize(cameraSize.wIDth,cameraSize.height);    }    parameters.setPictureFormat(ImageFormat.JPEG);    parameters.setJpegQuality(100);    parameters.setJpegthumbnailQuality(100);    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_auto);    camera.setParameters(parameters);    startOrIEntationchangelistener();}private voID startOrIEntationchangelistener() {    OrIEntationEventListener mOrEventListener = new    OrIEntationEventListener(MainActivity.this) {        @OverrIDe        public voID onorIEntationChanged(int rotation) {            if (((rotation >= 0) && (rotation <= 45)) || (rotation > 315)) {                rotation = 0;            } else if ((rotation > 45) && (rotation <= 135)) {                rotation = 90;            } else if ((rotation > 135) && (rotation <= 225)) {                rotation = 180;            } else if ((rotation > 225) && (rotation <= 315)) {                rotation = 270;            } else {                rotation = 0;            }            if (rotation == mOrIEntation)                return;            mOrIEntation = rotation;            updateCameraOrIEntation();        }    };    mOrEventListener.enable();} private voID updateCameraOrIEntation() {    if (camera != null) {        Camera.Parameters parameters = camera.getParameters();        int rotation = 90 + mOrIEntation == 360 ? 0 : 90 + mOrIEntation;        if (mIsFrontCamera) {            if (rotation == 90) rotation = 270;            else if (rotation == 270) rotation = 90;        }        parameters.setRotation(rotation);        camera.setdisplayOrIEntation(90);        camera.setParameters(parameters);    }}
解决方法 你可以从这个项目开始. https://github.com/pikanji/CameraPreviewSample 总结

以上是内存溢出为你收集整理的android自定义相机拉伸surfaceview全部内容,希望文章能够帮你解决android自定义相机拉伸surfaceview所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1123676.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存