我创建了一个基本服务,每 10 秒从相机获取图像。该服务运行良好,但我试图将图像文件命名为ImageYYYYddmm_HHmmSS。在第二个文件之后,图像得到相同的YYYYddmm_HHmmSS,从而覆盖了第一个图像。我的错误在哪里?
public class CP extends Service
{
Camera.PictureCallback mCall = new Camera.PictureCallback()
{
public void onPictureTaken(final byte[] data, Camera camera)
{
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream("/sdcard/Image"+tar+".jpg");
outStream.write(data); outStream.close();
Log.i("CAM", data.length + " byte written: /sdcard/Image"+tar+".jpg");
camClose(sHolder);
} catch (FileNotFoundException e){
Log.d("CAM", e.getMessage());
} catch (IOException e){
Log.d("CAM", e.getMessage());
}
}
};
@Override
public IBinder onBind(Intent intent) {
return null;
}
public void camClose(SurfaceHolder sHolder) {
if (null == mCamera)
return;
mCamera.stopPreview();
mCamera.release();
mCamera = null;
Log.i("CAM", " closed");
}
}