我正在尝试使用我创建的函数直接将位图保存到文件和特定文件.它不起作用.它在bitmap.compress部分之后崩溃(在here3之前).
File dir = new File(filepath);
if(!dir.exists())dir.mkdirs();
File file = new File(Environment.getExternalStorageDirectory() + filepath, side + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
System.out.println(filepath);
bitmap.recycle();
System.gc();
Run Code Online (Sandbox Code Playgroud)
错误日志:
06-29 00:16:38.089: D/AndroidRuntime(3260): Shutting down VM
06-29 00:16:38.089: W/dalvikvm(3260): threadid=1: thread exiting with uncaught exception (group=0xb587f4f0)
06-29 00:16:38.089: E/AndroidRuntime(3260): FATAL EXCEPTION: main
06-29 00:16:38.089: E/AndroidRuntime(3260): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=android.intent.action.VIEW dat=content://org.openintents.filemanager/mimetype//mnt/sdcard/download/02977_awreckedboatintheocean_1280x1024.jpg }} to activity {com.polygonattraction.testbirds/com.polygonattraction.testbirds.functions.SelectImageSource}: java.lang.IllegalStateException: Can't compress a recycled bitmap
06-29 00:16:38.089: E/AndroidRuntime(3260): …Run Code Online (Sandbox Code Playgroud)