0

LayoutView から取得したビットマップ イメージを保存する際に奇妙な問題が発生しています。以下のコードはビットマップを作成し、SD カードのパレット フォルダーに画像としてエクスポートする必要があります。それは実際にそれを行いますが、Gallery アプリを開くと、Camera フォルダーにビットマップの複製コピーもあります。Camera フォルダーに複製を作成せずに、フォルダーだけにコピーする方法はありますか? また、Camera フォルダー内の同じコピーを削除できる方法があれば、それも機能します。ありがとう!

LinearLayout paletteView = (LinearLayout)findViewById(R.id.ExportBitmapLayout);
paletteView.setDrawingCacheEnabled(true);
paletteView.buildDrawingCache();
Bitmap bm = paletteView.getDrawingCache();

String filename = "PALETTETITLE";
filename.toLowerCase();
filename.replace(" ","_");
filename = filename.substring(0, (filename.length() < 30) ? filename.length() : 29);

ContentValues values = new ContentValues();
values.put(Images.Media.DATE_ADDED, System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Images.Media.TITLE, filename);

boolean created = createDirIfNotExists("palettes");

if (created)
    Log.i("Directory created","OK");    
else
    Log.i("Directory exists","OK");

//if successful
try 
{
    OutputStream fOut = null;

    String longString = Environment.getExternalStorageDirectory()
            + File.separator + "palettes" +File.separator + filename+".jpg";

    File f = new File(longString);
    fOut = new FileOutputStream(f);

    bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);

    fOut.flush();
    fOut.close();

    MediaStore.Images.Media.insertImage(getContentResolver(), f.getAbsolutePath(), filename, filename);

    Context context = ExportMenuImageActivity.this.getApplicationContext();
    Toast toast = Toast.makeText(context, "Image saved to Gallery! NOTE: Unintentional save in Camera folder. Fix in next update.", Toast.LENGTH_LONG);
    toast.show();

    MediaScannerConnection.scanFile(context, new String[] {longString}, null, new MediaScannerConnection.OnScanCompletedListener() 
    {   
        public void onScanCompleted(String path, Uri uri) 
        {
        }
    });


}

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

catch (IOException e)
{
    e.printStackTrace();
}
4

1 に答える 1

1
Here is the complete solution of your problem.You can not do anything like protecting the camera folder to save images. But you can delete the latest image jsut after your image inserted inside the database.

Here is the code for deleting the latest file from the camera folder, Just do copy and paste it and call this method whenever you want to delete the latest file from you camera folder..


private void deleteLatest() {
        // TODO Auto-generated method stub
        File f = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera" );

        //Log.i("Log", "file name in delete folder :  "+f.toString());
        File [] files = f.listFiles();

        //Log.i("Log", "List of files is: " +files.toString());
        Arrays.sort( files, new Comparator<Object>()
                {
            public int compare(Object o1, Object o2) {

                if (((File)o1).lastModified() > ((File)o2).lastModified()) {
                    //         Log.i("Log", "Going -1");
                    return -1;
                } else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
                    //     Log.i("Log", "Going +1");
                    return 1;
                } else {
                    //     Log.i("Log", "Going 0");
                    return 0;
                }
            }

                });

        //Log.i("Log", "Count of the FILES AFTER DELETING ::"+files[0].length());
        files[0].delete();

    }

If still you have any query then let me know!!!
Cheers...
于 2012-07-25T05:36:07.607 に答える