在我的應用程序中,它會將圖像保存到SD卡中,然後用戶選擇如何處理它。刪除,保存或發送。如果你按刪除。我打電話給File.delete()
它會在我去看圖庫時刪除這些文件,然後當我稍後回來時,我會看到一個黑色圖像,表示文件無法加載。那張圖片是我之前試圖刪除的圖片。這有什麼問題,爲什麼不完全消失?File.delete()不會完全刪除留下的圖像空白圖像文件
我如何保存圖像:
public static File getOutputMediaFile(byte[] data){
image= BitmapFactory.decodeByteArray(data, 0, data.length);
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "FrontFlash");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()) return null;
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
@Override
public void onPictureTaken(byte[] data, Camera camera){
pictureFile = Util.getOutputMediaFile(data);
if (pictureFile == null){
Toast.makeText(this, "Couldn't create file", Toast.LENGTH_SHORT).show();
}
else{
try{
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
}
catch (FileNotFoundException e){
Toast.makeText(this, "File not found exception", Toast.LENGTH_SHORT).show();
}
catch (IOException e){
Toast.makeText(this, "IO Exception", Toast.LENGTH_SHORT).show();
}
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "FrontCam"))));
String photopath = pictureFile.getPath().toString();
//旋轉圖像
bmp = BitmapFactory.decodeFile(photopath);
matrix = new Matrix();
matrix.postRotate(270);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
FileOutputStream fOut;
try {
fOut = new FileOutputStream(pictureFile);
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
其中的onClick其中圖像刪除
public void exit(View view){
deleted = pictureFile.delete();
//startActivity(home);
close();
finish();
}
這是因爲庫尚未更新提到更新與一個特定的文件庫。觸發媒體掃描,它應該沒問題。 –
是不是這樣做,當它保存照片? 'sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse(「file://」+ new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),「FrontCam」))));' –
if no please please show me what to在刪除圖像後放置 –