我使用如下所示的代码在单击按钮时将 jpg 文件保存到 sdcard。
OutputStream fOut = null;
try
{
fOut = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
mMergedLayersBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
为了将图像保存到文件夹,我重写了代码,如下所示
OutputStream fOut = null;
//Create Folder
File folder = new File(Environment.getExternalStorageDirectory().toString()+"/draw/Images");
folder.mkdirs();
//Save the path as a string value
String extStorageDirectory = folder.toString();
//Create New file and name it draw.jpg
File file = new File(extStorageDirectory, "draw.jpg");
try
{
fOut = new FileOutputStream(file);
mMergedLayersBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
现在,当我第二次单击保存按钮时,它会重写图像。我想将我保存的整个图像保存到一个文件夹中。我不知道如何根据此要求更改我的代码。如果有人知道这件事,请帮助我..