在android中使用Image path添加图像

时间:2014-06-25 12:14:21

标签: android

我想从选择的图库中保存我的目录中的图像,所以我有保存动态图像的问题,保存我选择 那对我来说是什么解决方案

        Bitmap bitmap;
        OutputStream output;

        // Retrieve the image from the res folder
        bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.wallpaper);

        // Find the SD Card path
        File filepath = Environment.getExternalStorageDirectory();

        // Create a new folder in SD Card
        File dir = new File(filepath.getAbsolutePath()
                + "/Attitude/");
        dir.mkdirs();

        // Create a name for the saved image
        File file = new File(dir, "myimage.png");

        // Show a toast message on successful save
        Toast.makeText(MainActivity.this, "Image Saved to SD Card",
                Toast.LENGTH_SHORT).show();

        try {

            output = new FileOutputStream(file);

            // Compress into png format image from 0% - 100%
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
            output.close();
        }

        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
};

0 个答案:

没有答案