Camera preview on Android - weird on Samsung Galaxy S

In my activity, I show a camera preview on the surface of the View. It works great on Nexus One and HTC Desire, but on Samsung Galaxy S I see weird lines, weird proportions and all three times. see screenshot below.

The problem seems to be similar to this: camera preview on Android - strange lines on 1.5 sdk version but none of the comments there helped. I tried to change the height, width for the camera settings, but not a very big difference.

(Lateral note: my activity is always in landscape mode, fixed. I have this fix in my manifest as screenOrientation parameters, in case it matters).

Code of my SurfaceHolderCallback (corresponding 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

+4
source share
2 answers

I found that Samsung seems to have problems with the options

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

After splitting them, everything looks fine. I just need to rotate the image then manually.

+5
source

I probably state the obvious, but since your program works with both Nexus and Desire, your code is probably fine. Galaxy is a new phone - the problem is most likely a bug in your own drivers, not in your code. If so, it could be anything: you may just need to wait / hope for a patch.

+2
source

Source: https://habr.com/ru/post/1315205/


All Articles