0

Android の内部ストレージにビットマップを保存するこのコードをオンラインで見つけましたが、保存されていないように見えるか、画像が見つかりません。もしそうなら、これはどこに画像を保存しますか?

public boolean saveImageToInternalStorage(Bitmap image) {

    try {
        // Use the compress method on the Bitmap object to write image to
        // the OutputStream
        FileOutputStream fos = context.openFileOutput("desiredFilename.png", Context.MODE_PRIVATE);

        // Writing the bitmap to the output stream
        image.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.close();

        return true;
    } catch (Exception e) {
        Log.e("saveToInternalStorage()", e.getMessage());
        return false;
    }
}

ありがとう

4

1 に答える 1

1

簡単に説明しているこのブログ投稿を参照してください。

http://rajareddypolam.wordpress.com/?p=3&preview=true

&

この方法を試してください:

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");    
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}

あなたが忘れていたのは、画像を書く許可だったと思います

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
于 2013-08-15T09:51:07.247 に答える