繁体   English   中英

如何从文件调整图像大小?

[英]How resize image from file?

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

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

但这会带来错误。 我的错误在哪里? LogCat:

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)

您的错误是bitmaporgnull 从stacktrace中可以看到。 调整大小的实际代码看起来不错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM