簡體   English   中英

將圖像保存到內部存儲器

[英]Save image to internal storage

我想在內部存儲中保存一些圖像。 這是我的代碼:

Bitmap bitmap = ((BitmapDrawable)iv_add.getDrawable()).getBitmap();
            File file = getApplicationContext().getDir("Images",MODE_PRIVATE);
            file = new File(file, "UniqueFileName"+".jpg");
            try{
                OutputStream stream = null;
                stream = new FileOutputStream(file);
                bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
                stream.flush();
                stream.close();
            }catch (IOException e)
            {
                e.printStackTrace();
            }

據我了解,圖片需要進入internal_storage/android/data/project_name/file。 當我從我的圖庫中選擇一張圖片並單擊按鈕保存它時,沒有任何反應並且程序開始滯后。 我能做什么?

這條線是你的問題。

ContextWrapper wrapper = new ContextWrapper(getApplicationContext());

您不應該自己創建上下文包裝器。

        File file = getApplicationContext().getDir("Images",MODE_PRIVATE);
        file = new File(file, "UniqueFileName"+".jpg");
        try{
            OutputStream stream = null;
            stream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
            stream.flush();
            stream.close();
        }catch (IOException e)
        {
            e.printStackTrace();
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM