2016-09-20 2 views
0

ギャラリーに画像を保存するには、Clickメソッドを使用しています。画像がギャラリーアンドロイドビットマップに保存された後、「サムネイルなし」と表示されます

String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); 
       File myDir = new File(root + "/PhotoEditor "); 
       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); 
        if (sb != null) { 
         sb.compress(Bitmap.CompressFormat.JPEG, 90, out); 
        } 
        out.flush(); 
        out.close(); 
       } 
       catch (Exception e) { 
        e.printStackTrace(); 
       } 
       Toast.makeText(ShowPhotoActivity.this,"Your image is saved to gallery",Toast.LENGTH_LONG).show(); 


       // Tell the media scanner about the new file so that it is 
       // immediately available to the user. 
       MediaScannerConnection.scanFile(ShowPhotoActivity.this, new String[] { file.toString() }, null, 
         new MediaScannerConnection.OnScanCompletedListener() { 
          public void onScanCompleted(String path, Uri uri) { 
           Log.i("ExternalStorage", "Scanned " + path + ":"); 
           Log.i("ExternalStorage", "-> uri=" + uri); 
          } 
         }); 

答えて

0

は、あなたが「file.toStringを(ログインできます:私はクリックした後、フォルダがギャラリー内に作成された「保存」、しかし、私は、ギャラリーに行くとき、それは「何のサムネイルは」言わない... は、ここに私のコードです) "とあなたが得るものを参照してください? file.toString()を呼び出すのではなく、診断するのが難しい絶対パス、file.getAbsolutePath()を渡す必要があるかもしれません。ストリームを閉じた後にjpgが本当に存在することを確認するためにファイルマネージャーアプリケーションを使用しましたか?

+0

はい、私はビットマップを取得しないと思います。コードや何かを見せてもらえますか? –

関連する問題