2016-09-20 53 views
0

我有Click方法將圖像保存到圖庫中。之後我點擊「保存」的文件夾中創建的畫廊,但是當我去到畫廊它說:「沒有縮略圖」 ... 這裏是我的代碼:它表示圖像保存到圖庫後的「無縮略圖」 - android位圖

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.getAbsolutePath(),而不是調用file.toString(),但很難診斷。您是否已經使用文件管理器應用程序確認在關閉流之後jpg確實存在?

+0

是的,我認爲它沒有得到位圖。你能告訴我一個代碼什麼的嗎? –