1

我正在尝试更改文件夹中图像的大小。我写了这个:

FileOutputStream fos = new FileOutputStream(fullPath);
BitmapFactory.Options optsorg = new BitmapFactory.Options();
optsorg.inSampleSize = 2;
Bitmap bitmaporg = BitmapFactory.decodeFile(fullPath, optsorg);
bitmaporg = Bitmap.createScaledBitmap(bitmaporg, 600, 400, true);
bitmaporg.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();

但它给出了错误。我的错误在哪里?日志猫:

06-10 22:10:35.469: E/AndroidRuntime(22785): FATAL EXCEPTION: main
06-10 22:10:35.469: E/AndroidRuntime(22785): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {com.example.camerademo/com.example.camerademo.Main}: java.lang.NullPointerException
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3248)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread.access$1200(ActivityThread.java:140)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.os.Looper.loop(Looper.java:137)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread.main(ActivityThread.java:4921)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at java.lang.reflect.Method.invokeNative(Native Method)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at java.lang.reflect.Method.invoke(Method.java:511)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at dalvik.system.NativeStart.main(Native Method)
06-10 22:10:35.469: E/AndroidRuntime(22785): Caused by: java.lang.NullPointerException
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:461)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at com.example.camerademo.Main.onActivityResult(Main.java:73)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.Activity.dispatchActivityResult(Activity.java:5372)
06-10 22:10:35.469: E/AndroidRuntime(22785):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
4

1 回答 1

0

你的错误bitmaporgnull. 从堆栈跟踪中可以看出。调整大小的实际代码看起来不错。

于 2013-06-13T08:32:00.033 回答