从摄像头捕获的图像,它存储在SD卡/ DCIM文件夹 [英] Capturing image from Camera, it stores at sdcard/dcim folder
问题描述
我在我的应用程序使用摄像头捕获的图像。
1),它在SD卡保存图像,与我的意图传递的名字。
2)也保存图像的SD卡/ DCIM文件夹
我不希望相机保存的图像在#2中提到的位置。
我从位置#1删除图像。并希望在2号太从位置删除图像。
下面是用于捕捉图像code片段。
SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory()+文件分割符+tempImage.jpg
文件=新的文件(SD_CARD_TEMP_DIR);
意图takePictureFromCameraIntent =新意图(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(文件));
startActivityForResult(takePictureFromCameraIntent,TAKE_PICTURE_WITH_CAMERA);
这<一个href=\"http://stackoverflow.com/questions/8078892/stop-saving-photos-using-android-native-camera\">Thread帮我解决这个问题。
现在我在做什么,1)捕获图像,2)阅读新闻URI最后一个图像,并删除。
私人无效FillPhotoList(){
//初始化列表!
GalleryList.clear();
的String [] =投影{MediaStore.Images.ImageColumns.DISPLAY_NAME};
的for(int i = 0; I&LT; projection.length;我++)
Log.i(信息日志,投影+投影[0]的ToString());
// intialize的URI和光标,以及当前预期的大小。
光标C = NULL;
乌里U = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i(信息日志,FillPhoto乌里U+ u.toString());
//查询URI来获取数据路径。只有当URI是有效的。
如果(U!= NULL)
{
C = managedQuery(U,投影,NULL,NULL,NULL);
}
//如果我们发现光标并发现了一个纪录(我们也有ID)。
如果((C = NULL)及!及(c.moveToFirst()))
{
做
{
//每添加到列表中循环。
GalleryList.add(c.getString(0)); //添加在手机sotred的所有图像(内部和SD卡) }
而(c.moveToNext());
}
Log.i(信息日志,画廊大小+ GalleryList.size());
}
公共无效movingCapturedImageFromDCIMtoMerchandising()
{// 这是荒唐的。 Android的某些版本的保存
//为MediaStore为好。不知道为什么!我们不知道是什么
//名字Android将放弃要么,所以我们得到搜索此
//手动将其取出。
的String [] =投影{MediaStore.Images.ImageColumns.SIZE,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATA,
BaseColumns._ID,};
// intialize的URI和光标,以及当前预期的大小。的for(int i = 0; I&LT; projection.length;我++)
Log.i(关于activityresult投影,信息日志+投影[I]);
// ++投影[1] ++投影[2] ++投影[3]这将需要如果u删除循环
光标C = NULL;
乌里U = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i(信息日志,关于activityresult乌里U+ u.toString());如果(CurrentFile!= NULL)
{
//查询URI来获取数据路径。只有当URI是有效的,
//我们有一个有效的大小来寻找。
如果((U = NULL)及!及(CurrentFile.length()0))
{
// **** u是从数据的地方会和投影是指定的数据,我们想要什么
C = managedQuery(U,投影,NULL,NULL,NULL);
}
//如果我们发现光标并发现了一个纪录(我们也有大小)。
如果((C = NULL)及!及(c.moveToFirst()))
{
做
{
//检查我们以前建成的画廊每个区域。
布尔bFound = FALSE;
对于(字符串sGallery:GalleryList)
{
如果(sGallery.equalsIgnoreCase(c.getString(1)))
{
bFound = TRUE;
Log.i(信息日志,c.getString(1)+ c.getString(1));
打破;
}
}
//到这里循环充分画廊。
如果(!bFound)//这是新创建的文件,它必须从图库中删除
{
//这是新的形象。如果尺寸较大,将它复制。
//然后将其删除!
文件f =新的文件(c.getString(2));
//确保它的存在,检查大小和删除!
如果((f.exists())及及(CurrentFile.length()&所述; c.getLong(0))及及(CurrentFile.delete()))
{
//最后,我们可以停止复制。
尝试
{
CurrentFile.createNewFile();
FileChannel源= NULL;
FileChannel目的地= NULL;
尝试
{
来源=新的FileInputStream(F).getChannel();
目的地=新的FileOutputStream(CurrentFile).getChannel();
destination.transferFrom(源,0,source.size());
}
最后
{
如果(来源!= NULL)
{
source.close();
}
如果(目标!= NULL)
{
destination.close();
}
}
}
赶上(IOException异常E)
{
//无法将文件复制过来。
ToastMaker.makeToast(这一点,出错,0);
}
}
// ****删除这是在画廊中的文件
Log.i(信息日志,像preORNext1+图像preORNext);
处理程序处理程序=新的处理程序();
//handler.postDelayed(runnable,300);
Log.i(信息日志,像preORNext2+图像preORNext);
ContentResolver的CR = getContentResolver();
cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,BaseColumns._ID +=+ c.getString(3),空); 打破;
}
}
而(c.moveToNext());
}
} }
I am capturing image by using camera in my app.
1) it saves image at sdcard, with the name which i passed in intent.
2) also saving the image at sdcard/dcim folder
I do not want camera to save image at location mentioned in # 2. i am deleting image from the location in #1. and want to delete image from location in #2 too.
Below is the code snippet for capturing image.
SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "tempImage.jpg";
file =new File(SD_CARD_TEMP_DIR);
Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(takePictureFromCameraIntent, TAKE_PICTURE_WITH_CAMERA);
this Thread helped me to solve this problem. Now what I am doing, 1) capture image, 2) read last image in Media uri, and delete that.
private void FillPhotoList() {
// initialize the list!
GalleryList.clear();
String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME };
for(int i=0;i<projection.length;i++)
Log.i("InfoLog","projection "+projection[0].toString());
// intialize the Uri and the Cursor, and the current expected size.
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","FillPhoto Uri u "+u.toString());
// Query the Uri to get the data path. Only if the Uri is valid.
if (u != null)
{
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the id).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Loop each and add to the list.
GalleryList.add(c.getString(0)); // adding all the images sotred in the mobile phone(Internal and SD card)
}
while (c.moveToNext());
}
Log.i(INFOLOG,"gallery size "+ GalleryList.size());
}
public void movingCapturedImageFromDCIMtoMerchandising()
{
// This is ##### ridiculous. Some versions of Android save
// to the MediaStore as well. Not sure why! We don't know what
// name Android will give either, so we get to search for this
// manually and remove it.
String[] projection = { MediaStore.Images.ImageColumns.SIZE,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATA,
BaseColumns._ID,};
// intialize the Uri and the Cursor, and the current expected size.
for(int i=0;i<projection.length;i++)
Log.i("InfoLog","on activityresult projection "+projection[i]);
//+" "+projection[1]+" "+projection[2]+" "+projection[3] this will be needed if u remove the for loop
Cursor c = null;
Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Log.i("InfoLog","on activityresult Uri u "+u.toString());
if (CurrentFile != null)
{
// Query the Uri to get the data path. Only if the Uri is valid,
// and we had a valid size to be searching for.
if ((u != null) && (CurrentFile.length() > 0))
{
//****u is the place from data will come and projection is the specified data what we want
c = managedQuery(u, projection, null, null, null);
}
// If we found the cursor and found a record in it (we also have the size).
if ((c != null) && (c.moveToFirst()))
{
do
{
// Check each area in the gallery we built before.
boolean bFound = false;
for (String sGallery : GalleryList)
{
if (sGallery.equalsIgnoreCase(c.getString(1)))
{
bFound = true;
Log.i("InfoLog","c.getString(1) "+c.getString(1));
break;
}
}
// To here we looped the full gallery.
if (!bFound) //the file which is newly created and it has to be deleted from the gallery
{
// This is the NEW image. If the size is bigger, copy it.
// Then delete it!
File f = new File(c.getString(2));
// Ensure it's there, check size, and delete!
if ((f.exists()) && (CurrentFile.length() < c.getLong(0)) && (CurrentFile.delete()))
{
// Finally we can stop the copy.
try
{
CurrentFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(f).getChannel();
destination = new FileOutputStream(CurrentFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally
{
if (source != null)
{
source.close();
}
if (destination != null)
{
destination.close();
}
}
}
catch (IOException e)
{
// Could not copy the file over.
ToastMaker.makeToast(this, "Error Occured", 0);
}
}
//****deleting the file which is in the gallery
Log.i(INFOLOG,"imagePreORNext1 "+imagePreORNext);
Handler handler = new Handler();
//handler.postDelayed(runnable,300);
Log.i(INFOLOG,"imagePreORNext2 "+imagePreORNext);
ContentResolver cr = getContentResolver();
cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, BaseColumns._ID + "=" + c.getString(3), null);
break;
}
}
while (c.moveToNext());
}
}
}
这篇关于从摄像头捕获的图像,它存储在SD卡/ DCIM文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!