Android上的相机预览 - 三星Galaxy S上的奇怪 [英] Camera preview on Android - strange on Samsung Galaxy S

查看:18
本文介绍了Android上的相机预览 - 三星Galaxy S上的奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的活动中,我在 SurfaceView 上显示相机预览.它在 Nexus One 和 HTC Desire 上运行得非常好,但在三星 Galaxy S 上,我看到奇怪的线条、奇怪的比例和一切三倍.请参阅下面的屏幕截图.

In my activity I show the camera preview on a surfaceView. It works perfectly fine on Nexus One and HTC Desire, but on Samsung Galaxy S I see strange lines, weird proportions and everything three times. see the Screenshot below.

这个问题似乎和这个类似:android上的相机预览-奇怪的线条1.5版本的sdk但那里的评论都没有帮助.我尝试用相机参数交换高度,宽度,但差别不大.

The issue seems to be similar to this one: camera preview on android - strange lines on 1.5 version of sdk but none of the comments there helped. I tried to swap height,width for the camera parameters, but not much of a difference.

(旁注:我的活动始终处于横向模式,已修复.我在清单中将该修复作为 screenOrientation 参数,以防万一这很重要).

(Side note: my activity is always in landscape mode, fixed. I have that fix in my manifest as screenOrientation parameters, in case that matters somehow).

我的 SurfaceHolderCallback 的代码(我活动中的相关内部类):

The code of my SurfaceHolderCallback (the relevant inner class in my activity):

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) {
        camera = Camera.open(); 

        //Surface.setOrientation(Display.DEFAULT_DISPLAY,Surface.ROTATION_90);            
        Parameters p = camera.getParameters();
        p.setPictureSize(IMAGE_WIDTH, IMAGE_HEIGHT);
        p.set(ORIENTATION, PORTRAIT);
        p.set(ROTATION, 90);
        // p.setPreviewSize(640, 480);

        Camera.Size s = p.getSupportedPreviewSizes().get(0);
        Log.d(APP, "preview params " + s.width +"/"+ s.height);            
        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;
    }

    ...

推荐答案

发现三星好像参数有问题

I found that Samsung seems to have problems with the parameters

p.set("orientation", "portrait");
p.set("rotation", 90);

取消注释后,它看起来没问题.之后我只需要手动旋转图像即可.

After uncommenting those, it looks ok. I just need to rotate the image afterwards manually then.

这篇关于Android上的相机预览 - 三星Galaxy S上的奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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