0
今天早上我被困在這裏:圖像沒有被創建在文件夾中。
你能幫我,告訴我爲什麼它不起作用嗎?圖像沒有被保存在文件夾中
這是正確的獲取圖像?
Bundle extras = data.getExtras();
Bitmap imageToSave = extras.getParcelable("data");
這是我的全部代碼
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
final File path =
Environment.getExternalStoragePublicDirectory
(
// Environment.DIRECTORY_PICTURES + "/ss/"
//Environment.DIRECTORY_DCIM
Environment.DIRECTORY_DCIM + "/MyFolderName/"
);
// Make sure the Pictures directory exists.
if(!path.exists())
{
path.mkdirs();
}
// Bitmap imageToSave = (Bitmap) data.getExtras().get("data");
// Bitmap imageToSave = (Bitmap) data.getData();
Bundle extras = data.getExtras();
Bitmap imageToSave = extras.getParcelable("data");
final File file = new File(path, "file" + ".jpg");
try {
FileOutputStream fos = new FileOutputStream(path);
final BufferedOutputStream bos = new BufferedOutputStream(fos, 8192);
FileOutputStream out = new FileOutputStream(path);
//fos = new FileOutputStream(path);
imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, fos);
// imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Uri selectedImage = data.getData();
Intent i = new Intent(this,
AddImage.class);
i.putExtra("imagePath", selectedImage.toString());
startActivity(i);
}
}}
我複製你的代碼,因爲它是,並且圖像wasent保存,我缺少什麼,你是如何指定的文件夾名稱? – Moudiz
關於它的更多信息:http://stackoverflow.com/a/8737101/2649012 –
我對你的代碼進行了更多的搜索,並且我得到了這個例子,它也幫助了我http://www.geeks.gallery/saving-image/ ..謝謝你幫助我 – Moudiz