栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

无法连接相机服务

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无法连接相机服务

供您参考,这是我在应用程序中使用的SurfaceHolderCallBack内部类,该类在纵向模式下的Nexus One 2.2上运行良好-
希望对您有所帮助。

编辑:“这有效”
=“这不会崩溃”。尽管我还没有弄清楚如何正确旋转预览图像(请参阅上面的第一条评论)。这就是为什么我实际上必须使用横向并将预览表面周围的UI内容“转换”为横向模式的原因。Afaik预览(正确旋转预览图像)仅在横向模式下有效。我尝试过的旋转和方向参数完全没有帮助。

class SurfaceHolderCallback implements SurfaceHolder.Callback {    private static final int IMAGE_WIDTH = 512;    private static final int IMAGE_HEIGHT = 384;    private static final String ORIENTATION = "orientation";    private static final String ROTATION = "rotation";    private static final String PORTRAIT = "portrait";    private static final String LANDSCAPE = "landscape";    public void surfaceCreated(SurfaceHolder holder) {        try { // This case can actually happen if the user opens and closes the camera too frequently. // The problem is that we cannot really prevent this from happening as the user can easily // get into a chain of activites and tries to escape using the back button. // The most sensible solution would be to quit the entire EPostcard flow once the picture is sent. camera = Camera.open();        } catch(Exception e) { finish(); return;        }        //Surface.setOrientation(Display.DEFAULT_DISPLAY,Surface.ROTATION_90);        Parameters p = camera.getParameters();        p.setPictureSize(IMAGE_WIDTH, IMAGE_HEIGHT);        camera.getParameters().setRotation(90);        Camera.Size s = p.getSupportedPreviewSizes().get(0);        p.setPreviewSize( s.width, s.height );        p.setPictureFormat(PixelFormat.JPEG);        p.set("flash-mode", "auto");        camera.setParameters(p);        try { camera.setPreviewDisplay(surfaceHolder);        } catch (Throwable ignored) { Log.e(APP, "set preview error.", ignored);        }    }    public void surfaceChanged(SurfaceHolder holder, int format, int width,         int height) {        if (isPreviewRunning) { camera.stopPreview();        }        try { camera.startPreview();        } catch(Exception e) { Log.d(APP, "Cannot start preview", e); }        isPreviewRunning = true;    }    public void surfaceDestroyed(SurfaceHolder arg0) {        if(isPreviewRunning && camera != null) { if(camera!=null) {     camera.stopPreview();     camera.release();       camera = null; } isPreviewRunning = false;        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404328.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号