tags:

views:

187

answers:

2

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.

The issue seems to be similar to this one: http://stackoverflow.com/questions/2053440/camera-preview-on-androd-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.

(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).

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;
    }

    ...

alt text

+1  A: 

I'm probably stating the obvious, but since your program works on both the Nexus and Desire your code is probably fine. The Galaxy is a new phone--the issue is likely a bug in its own drivers, not your code. If that is the case, it could be anything: you may just need to wait/hope for a patch.

SirBoss
+2  A: 

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.

Mathias Lin