Any problems taking a portrait photo when device i

2019-08-09 06:38发布

问题:

I am making a rather specialist camera app for a device which is physically always going to be held in a landscape orientation. Part of the spec is that it must be able to preview and take photos in a portrait orientation - see image below.

I am having some trouble with a runtime exception "setParameters failed" (in response to a call to camera.setParameters()) and I just wanted to check here whether there was some fundamental problem that you think I might be up against. For example perhaps the light sensors on the back of the camera are a arranged in a rectangle and physically this can not be achieved - or perhaps some other unavoidable issue. (By the way I have been informed that the light sensors should be arranged in a square, so this problem will not occur - but my sources may be mistaken). Maybe this is hardware dependant?

EDIT: FYI my crash log is below:

D/AndroidRuntime(7210): Shutting down VM
W/dalvikvm(7210): threadid=1: thread exiting with uncaught exception (group=0x415c2d88)
E/AndroidRuntime(7210): FATAL EXCEPTION: main
E/AndroidRuntime(7210): Process: com.rai.motion, PID: 7210
E/AndroidRuntime(7210): java.lang.RuntimeException: Unable to resume activity {com.rai.motion/com.rai.motion.MotionMain}: java.lang.RuntimeException: setParameters failed
E/AndroidRuntime(7210):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2850)
E/AndroidRuntime(7210):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2879)
E/AndroidRuntime(7210):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2303)
E/AndroidRuntime(7210):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime(7210):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
E/AndroidRuntime(7210):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(7210):     at android.os.Looper.loop(Looper.java:212)
E/AndroidRuntime(7210):     at android.app.ActivityThread.main(ActivityThread.java:5151)
E/AndroidRuntime(7210):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(7210):     at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(7210):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime(7210):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime(7210):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(7210): Caused by: java.lang.RuntimeException: setParameters failed
E/AndroidRuntime(7210):     at android.hardware.Camera.native_setParameters(Native Method)
E/AndroidRuntime(7210):     at android.hardware.Camera.setParameters(Camera.java:1689)
E/AndroidRuntime(7210):     at com.rai.motion.MotionMain.change_java_recording_camera_settings(MotionMain.java:2105)
E/AndroidRuntime(7210):     at com.rai.motion.MotionMain.start_recording_camera(MotionMain.java:2154)
E/AndroidRuntime(7210):     at com.rai.motion.MotionMain.onResume(MotionMain.java:6013)
E/AndroidRuntime(7210):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
E/AndroidRuntime(7210):     at android.app.Activity.performResume(Activity.java:5310)
E/AndroidRuntime(7210):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2840)
E/AndroidRuntime(7210):     ... 12 more
I/Process(7210): Sending signal. PID: 7210 SIG: 9

回答1:

I made a small camera test app a while ago. It was no problem, to show the camera preview in portrait mode, whilst the device was in landscape orientation. It was tricky to rotate the camera image by the right angle (because this rotation angle is device/camera dependant). A problem however was, that the perspective didn't match then: object seemed to be fatter or streched. But to find out the recalculating algorithm shouldn't take to much time on Stackoverflow.

So regarding

I just wanted to check here whether there was some fundamental problem that you think I might be up against.

[...]and physically this can not be achieved - or perhaps some other unavoidable issue.

the answer is: it's a doable task. Your exception probably has a totally different reason.