android– 双重保存图片

android– 双重保存图片,第1张

概述我用过手册http://developer.android.com/guideopics/media/camera.html但我有一个问题.此代码保存图像两次.第一张图片保存在/sdcard/DCIM/Camera中,第二张图片保存在/sdcard/PicturesMyCameraApp中.如何删除第一次保存到/sdcard/DCIM/Camera.感谢帮助publicvo

我用过手册
http://developer.android.com/guide/topics/media/camera.html
但我有一个问题.此代码保存图像两次.第一张图片保存在/ sdcard / DCIM / Camera中,第二张图片保存在/ sdcard / PicturesMyCameraApp中.如何删除第一次保存到/ sdcard / DCIM / Camera.
感谢帮助

public voID onClick(VIEw v) {    // Todo auto-generated method stub    switch (v.getID()) {        case R.ID.imagebutton1:            Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);            i.putExtra(MediaStore.EXTRA_OUTPUT, getoutputMediafileUri());            startActivityForResult(i, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);        break;    }}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu){    MenuInflater inflater = getMenuInflater();    inflater.inflate(R.menu.mainmenu, menu);    return true;}@OverrIDepublic boolean onoptionsItemSelected(MenuItem item){    switch (item.getItemID()) {        case R.ID.item1:            /*Intent intent = new Intent(ZodiacActivity.this, AboutActivity.class);            startActivity(intent);*/        break;        case R.ID.item2:            this.moveTaskToBack(true);        break;    }    return true;}@OverrIDeprotected voID onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);      if (requestCode==CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {        if (resultCode==RESulT_OK) {            Toast.makeText(this, "uloženo do: " + getoutputMediafileUri().toString(), Toast.LENGTH_LONG).show();        }        else {            return;        }    }}public Uri getoutputMediafileUri(){      return Uri.fromfile(getoutputMediafile());}public file getoutputMediafile(){    // To be safe, you should check that the SDCard is mounted    // using Environment.getExternalStorageState() before doing this.    file mediaStorageDir = new file(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp");    // This location works best if you want the created images to be shared    // between applications and persist after your app has been uninstalled.    // Create the storage directory if it does not exist    if (! mediaStorageDir.exists()){        if (! mediaStorageDir.mkdirs()){            Log.d("MyCameraApp", "Failed to create directory");            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;}

解决方法:

您只需删除该文件:

String pathTofile = "/sdcard/DCIM/Camera/imagename.jpg";boolean success = new file(pathTofile).delete();if(success){// deleting file succeeded}else{// it dIDn't succeed}

编辑

在/ sdcard / DCIM /相机中获取最新拍摄的照片:

file[] images = new file("/sdcard/DCIM/Camera").Listfiles();file latestSavedImage = images[0];for(int i=1; i<images.length; ++i){ if(images[i].lastModifIEd() > latestSavedImage.lastModifIEd()){   latestSavedImage = image; }}

注意,代码没有经过测试!

总结

以上是内存溢出为你收集整理的android – 双重保存图片全部内容,希望文章能够帮你解决android – 双重保存图片所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1097370.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存