我正在开发基于相机功能的安卓应用程序。我在我的程序中遇到了一些麻烦,我无法弄清楚。我的mCurrentImagePath
在初始化时始终为空。 logcat显示它从来没有击中takepicture()
函数,所以它永远不会被赋予一个值。我试图让线程睡眠,以便稍后对位图的操作可以等待,直到相机保存好图像,但仍然不起作用。但如果我没有阅读我拍摄的照片,应用程序完美无缺,它可以很好地保存照片。我也尝试使用bitmapfactory.decodebyte()
直接操作元数据,但也失败了。任何人都可以告诉我哪一部分我错了?这将非常有帮助。非常感谢你!!!安卓相机保存文件错误
private static final String IMAGE_DIRECTORY ="sdcard/DCIM/Camera";
public static String mCurrentImagePath = null;
private CameraView cv;
private Camera mCamera = null;
public Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
try{
isFinish = false;
long timeTaken = System.currentTimeMillis();
mCurrentImagePath = IMAGE_DIRECTORY + "/"+ createName(timeTaken) + ".jpg";
File file = new File(mCurrentImagePath);
Log.d("path", "mCurrentImagePath_takepicture = " + mCurrentImagePath);
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.flush();
fos.close();
Toast.makeText(OpenASURF.this, "saving the picture", Toast.LENGTH_SHORT).show();
isFinish = true;
}
catch(IOException e) {
e.printStackTrace();
}
mCamera.startPreview();
// TODO Auto-generated method stub
}
};
cv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mCamera != null) {
mCamera.takePicture(null, null, pictureCallback);
// let the system wait until finish taking the pictures.
//while(isFinish == false) {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
Log.d("path", "mCurrentImagePath_over1 = " + mCurrentImagePath);
Bitmap bmp = null;
bmp = BitmapFactory.decodeFile(mCurrentImagePath);
Log.d("path", "mCurrentImagePath_over2 = " + mCurrentImagePath);
}
谢谢你的建议,它真的让我对这个问题感到头疼。我试图将我的计算部分添加到onPictureTaken()中,但它也显示OutofMemoryError。你有什么想法吗? – Zhuorui
什么计算? –
我将使用我从相机拍摄的图片进行图像识别。我将计算它的SURF描述符以进一步匹配。 – Zhuorui