我有拍照的相机应用程序。我的问题是当我拍照时它是 240*320 但我的相机可以拍摄高清照片。我怎样才能用我的相机拍摄高支持的照片?我试试这段代码:
public void GetHighResolutionForCamera(){
int Max = 0;
Camera.Size MR = null ;
Parameters params = mCamera.getParameters();
List<Camera.Size> resolution ;
resolution = params.getSupportedPictureSizes();
for (Camera.Size size : resolution) {
if(Max < size.height){
MR = size ;
Max = size.height;
}
}
params.setPictureSize(MR.width, MR.height);
mCamera.setParameters(params);
}
但是尝试设置参数时出现错误。这与表面视图有关吗?我什么时候可以为我的相机设置参数?
这是日志猫:
08-21 22:21:27.442: D/AndroidRuntime(27812): Shutting down VM
08-21 22:21:27.442: W/dalvikvm(27812): threadid=1: thread exiting with uncaught exception (group=0x41a5e700)
08-21 22:21:27.458: E/AndroidRuntime(27812): FATAL EXCEPTION: main
08-21 22:21:27.458: E/AndroidRuntime(27812): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mytackpicture/com.example.mytackpicture.MainActivity}: java.lang.NullPointerException
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.os.Looper.loop(Looper.java:137)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 22:21:27.458: E/AndroidRuntime(27812): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 22:21:27.458: E/AndroidRuntime(27812): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 22:21:27.458: E/AndroidRuntime(27812): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 22:21:27.458: E/AndroidRuntime(27812): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 22:21:27.458: E/AndroidRuntime(27812): at dalvik.system.NativeStart.main(Native Method)
08-21 22:21:27.458: E/AndroidRuntime(27812): Caused by: java.lang.NullPointerException
08-21 22:21:27.458: E/AndroidRuntime(27812): at com.example.mytackpicture.MainActivity.GetHighResolutionForCamera(MainActivity.java:63)
08-21 22:21:27.458: E/AndroidRuntime(27812): at com.example.mytackpicture.MainActivity.onCreate(MainActivity.java:57)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.Activity.performCreate(Activity.java:5133)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 22:21:27.458: E/AndroidRuntime(27812): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 22:21:27.458: E/AndroidRuntime(27812): ... 11 more