2016-03-05 52 views

回答

1

可以包含在Android應用程序文件夾中的照片,獲得高分辨率的文件有必要把它們存放到外廊,並告訴你的檔案庫和應用程序文件夾,並顯示您的文件作爲縮略圖,讓我實現這個方法其中執行我需要什麼,我希望幫助別人

private void SaveImage(Bitmap segg) { 

    OutputStream fOut = null; 
    Random generator = new Random(); 
    int n = 10000; 
    n = generator.nextInt(n); 
    String fileName = "Image-"+ n +".png"; 
    final String appDirectoryName = "TBStego"; 
    final File imageRoot = new File(Environment.getExternalStoragePublicDirectory(
      Environment.DIRECTORY_PICTURES), appDirectoryName); 

    imageRoot.mkdirs(); 
    final File file = new File(imageRoot, fileName); 
    try { 
     fOut = new FileOutputStream(file); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

    segg.compress(Bitmap.CompressFormat.PNG, 100, fOut); 
    try { 
     Toast.makeText(ExtractActivity.this, 
       file.getAbsolutePath(), 
       Toast.LENGTH_LONG).show(); 
     fOut.flush(); 
     fOut.close(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    ContentValues values = new ContentValues(); 
    values.put(MediaStore.Images.Media.TITLE,"stego"); 
    values.put(MediaStore.Images.Media.DESCRIPTION, "stego description"); 
    values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis()); 
    values.put(MediaStore.Images.ImageColumns.BUCKET_ID, file.toString().toLowerCase(Locale.US).hashCode()); 
    values.put(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, file.getName().toLowerCase(Locale.US)); 
    values.put("_data", file.getAbsolutePath()); 
    Toast.makeText(ExtractActivity.this, 
      file.getAbsolutePath(), 
      Toast.LENGTH_LONG).show(); 
    ContentResolver cr = getContentResolver(); 
    cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
    Toast.makeText(ExtractActivity.this, "The Image thumbnail created in Gallery ", Toast.LENGTH_LONG).show(); 
}