题
我碰到了一个问题与我可能只是忽视的东西。
我想利用从摄像机的表面预览图像,然后将其保存到sd_card
。这工作近乎完美。我赋予它一个文件名,但它不使用filename
。
这是我一直在努力做的事情:
Button imagecapture = (Button) findViewById(R.id.imagecapture);
imagecapture.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String filename = null;
ImageCaptureCallback iccb = null;
try {
filename = timeStampFormat.format(new Date());
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
values.put(Media.DESCRIPTION, "Image capture by camera");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
iccb = new ImageCaptureCallback(getContentResolver().openOutputStream(uri));
} catch (Exception ex) {
ex.printStackTrace();
Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
}
camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
com.froogloid.android.gspot.Park.imageFileName = filename;
}
});
有将不使用的文件名(即,时间/日期戳我它问。)
解决方案
这是通过经由ImageCaptureCallback类实施PictureCallback,以及重写该文件被经由一个文件输出流写入的onPictureTaken解决。所有你需要做的就是改变在FileOutput流到你想要的文件名。
其他提示
它不保存图像?在我的应用程序的代码保存图片,也许你使用变量“filaname”从SD卡获取图像?使用图像SD卡从更好是在变量来保存,对于examople,uri.toString的“fileURI所”的值,结束从与URI Uri.parse(fileURI所)SD卡文件获得..
希望这有助于/或许不会去了解它的最佳方式,但它的工作。 在这里你去:点击 这是在摄像机捕获图像回调强>
public class ImageCaptureCallback implements PictureCallback {
private OutputStream filoutputStream;
public ImageCaptureCallback(OutputStream filoutputStream) {
this.filoutputStream = filoutputStream;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
FileOutputStream buf = new FileOutputStream("/sdcard/dcim/Camera/" + CameraActivity.filename + ".jpg");
buf.write(data);
buf.flush();
buf.close();
// filoutputStream.write(data);
filoutputStream.flush();
filoutputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
不隶属于 StackOverflow