小编Dhe*_*ngh的帖子

将位图保存到文件功能

我正在尝试使用我创建的函数直接将位图保存到文件和特定文件.它不起作用.它在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)

file-io android bitmap android-intent android-file

35
推荐指数
4
解决办法
9万
查看次数

禁用自动更改方向

以下是我的代码.
我想设置它禁用自动更改屏幕方向.
并启用自动更改屏幕方向.

class NewLoad extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progDailog = new ProgressDialog(this);
            progDailog.setMessage("test");
            progDailog.setIndeterminate(false);
            progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progDailog.setCancelable(false);
            progDailog.show();
            //set disable auto change
        }

        @Override
        protected String doInBackground(String... aurl) {
            //do something
            return null;
        }

        @Override
        protected void onPostExecute(String unused) {
            super.onPostExecute(unused);
            progDailog.dismiss();
            //set enable auto change
        }
    }
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

android

3
推荐指数
1
解决办法
1568
查看次数

标签 统计

android ×2

android-file ×1

android-intent ×1

bitmap ×1

file-io ×1