接上: FireEye.SavePicture();
private void SavePicture()
{
if (this.mTakeImageStatus)
{
if (this.mConfig.getRecordModeValue() != 0)
break label71;
this.mCurrentVideoUri = FileStorage.AddImageToMediaStore(this.mContentResolver, 0L, this.mConfig.FrontSensorID);
}
for (this.mCurrentVideoUri = FileStorage.AddImageToMediaStore(this.mContentResolver, 0L, this.mConfig.BackSensorID); ; this.mCurrentVideoUri = FileStorage.AddImageToMediaStore(this.mContentResolver, 0L, this.mConfig.FrontSensorID))
{
this.mStartWork.setBackgroundResource(2130837584);
this.mTakeImageStatus = false;
label71: return;
}
}
整理后:
private void SavePicture()
{
if (mTakeImageStatus)
{
if (mConfig.getRecordModeValue() == 0)//判断是录像模式还是拍照模式
mCurrentVideoUri = FileStorage.AddImageToMediaStore(mContentResolver, 0L, mConfig.FrontSensorID);
}
for (mCurrentVideoUri = FileStorage.AddImageToMediaStore(mContentResolver, 0L, mConfig.BackSensorID); ; mCurrentVideoUri = FileStorage.AddImageToMediaStore(mContentResolver, 0L, mConfig.FrontSensorID))
{
mStartWork.setBackgroundResource(R.drawable.camera_stop_work);
mTakeImageStatus = false;
}
}
转到FileStorage.java:
public static Uri AddImageToMediaStore(ContentResolver paramContentResolver, long paramLong, int paramInt)
{
ContentValues localContentValues = new ContentValues(7);
localContentValues.put("title", mImageTitle[paramInt]);
localContentValues.put("_display_name", mImageTitle[paramInt] + ".jpg");
localContentValues.put("datetaken", Long.valueOf(mImageDate[paramInt]));
localContentValues.put("mime_type", "image/jpeg");
localContentValues.put("_data", mImageFilename[paramInt]);
if (paramLong > 0L)
localContentValues.put("orientation", Long.valueOf(paramLong));
while (true)
{
Object localObject = null;
try
{
Uri localUri = paramContentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues);
localObject = localUri;
if (CODE_DEBUG)
label124: Log.d("FileStorage", "AddImageToMediaStore uri :" + localObject);
return localObject;
Log.w("FileStorage", "Image duration <= 0 : " + paramLong);
}
catch (Throwable localThrowable)
{
Log.d("FileStorage", "Failed to write MediaStore" + localThrowable);
break label124:
}
}
}
整理后:
public static Uri AddImageToMediaStore(ContentResolver paramContentResolver, long paramLong, int paramInt)
{
ContentValues localContentValues = new ContentValues(7);
localContentValues.put(MediaStore.Images.ImageColumns.TITLE, mImageTitle[paramInt]);
localContentValues.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageTitle[paramInt] + ".jpg");
localContentValues.put(MediaStore.Images.ImageColumns.DATE_TAKEN, Long.valueOf(mImageDate[paramInt]));
localContentValues.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/jpeg");
localContentValues.put(MediaStore.Images.ImageColumns.DATA, mImageFilename[paramInt]);
if (paramLong > 0L)
localContentValues.put("orientation", Long.valueOf(paramLong));
else
<span style="white-space:pre"> </span>Log.w("FileStorage", "Image duration <= 0 : " + paramLong);<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>
while (true)
{
Object localObject = null;
try
{
Uri localUri = paramContentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues);
localObject = localUri;
if (CODE_DEBUG)
Log.d("FileStorage", "AddImageToMediaStore uri :" + localObject);
return localObject;
}
catch (Throwable localThrowable)
{
Log.d("FileStorage", "Failed to write MediaStore" + localThrowable);
}
}
}
在(一)中有介绍
AddVideoToMediaStore,基本上是一样的处理。
关键就两点:1、存储图片是的对db基本格式的填写
localContentValues.put
2、在指定的路径中插入数据:
Uri localUri = paramContentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, localContentValues);