Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从getExternalStorageDirectory到内部存储_Java_Android_Eclipse_Storage - Fatal编程技术网

Java 从getExternalStorageDirectory到内部存储

Java 从getExternalStorageDirectory到内部存储,java,android,eclipse,storage,Java,Android,Eclipse,Storage,我再次需要你的帮助。我有这个简单的照片应用程序的代码,但这个代码保存在SD卡编辑的图像,但我想改变这个保存在手机内存的图像 private File captureImage() { // TODO Auto-generated method stub OutputStream output; Calendar cal = Calendar.getInstance(); Bitmap bitmap = Bitmap.createBitmap(ll1.getWi

我再次需要你的帮助。我有这个简单的照片应用程序的代码,但这个代码保存在SD卡编辑的图像,但我想改变这个保存在手机内存的图像

private File captureImage() {
    // TODO Auto-generated method stub
    OutputStream output;

    Calendar cal = Calendar.getInstance();

    Bitmap bitmap = Bitmap.createBitmap(ll1.getWidth(), ll1.getHeight(),
            Config.ARGB_8888);

    /*
     * bitmap = ThumbnailUtils.extractThumbnail(bitmap, ll1.getWidth(),
     * ll1.getHeight());
     */
    Canvas b = new Canvas(bitmap);
    ll1.draw(b);

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

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

    mImagename = "image" + cal.getTimeInMillis() + ".png";

    // Create a name for the saved image
    file = new File(dir, mImagename);

    // Show a toast message on successful save
    Toast.makeText(SelectedImgActivity.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.flush();
        output.close();
    }

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

    return file;

}
有什么建议吗?我想我必须只将Environment.getExternalStorageDirectory更改为其他内容,但是什么呢

谢谢大家!

编辑:

我将这一行更改为
filepath=Environment.getDataDirectory();我认为这是可行的。但是这个在根文件夹中创建新文件夹…我希望它在图片中。。。如何对此进行存档?

编辑2:

现在我被编辑成这个代码

private File captureImage() {
    // TODO Auto-generated method stub
    OutputStream output;

    Calendar cal = Calendar.getInstance();

    Bitmap bitmap = Bitmap.createBitmap(ll1.getWidth(), ll1.getHeight(),
            Config.ARGB_8888);

    /*
     * bitmap = ThumbnailUtils.extractThumbnail(bitmap, ll1.getWidth(),
     * ll1.getHeight());
     */
    Canvas b = new Canvas(bitmap);
    ll1.draw(b);

    // Find the SD Card path
    File filepath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
//  File filepath = Environment.getDataDirectory(Environment.DIRECTORY_PICTURES);

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

    dir.mkdirs();

    mImagename = "image" + cal.getTimeInMillis() + ".png";

    // Create a name for the saved image
    file = new File(dir, mImagename);

    // Show a toast message on successful save
    Toast.makeText(SelectedImgActivity.this, "Image Saved",
            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.flush();
        output.close();
    }

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

    return file;

}
一切都很好,除了吐司秀

替换:

File dir = new File(filepath.getAbsolutePath() + "/background_eraser/");
与:

您可以使用:

FileInputStream fis = context.openFileInput(name);
在API级别1中添加

返回文件系统上存储使用openFileOutput(String,int)创建的文件的目录的绝对路径

FileInputStream fis = context.openFileInput(name);