java程序照片文件的删除不了怎么办_java – File.delete()没有完全删除留下的图像空白图像文件...

在我的应用程序中,您需要将照片保存到SD卡,然后用户可以选择如何处理它.删除,保存或发送.如果按删除.我调用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();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值