Android:从相机获取文件名? [英] Android: Getting file name from camera?
问题描述
我遇到了可能只是被我忽略的问题.
I ran into an issue with something that I am probably just overlooking.
我想从相机的表面预览中拍摄照片,并将其保存到sd_card
.这几乎完美.我给它分配了一个文件名,但它不使用filename
.
I want to take a picture from the surface preview of the camera, and save it to the sd_card
. This works ALMOST perfect. I assigned it a file name, but it does not use the filename
.
这就是我一直在尝试的事情:
This is what I have been trying to do :
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;
}
});
它不会使用文件名(即我要求的时间/日期戳).
It won't use the filename (i.e. time/date stamp I ask it to.)
推荐答案
此问题的解决方法是通过ImageCaptureCallback类实现PictureCallback,然后重写通过文件输出流将文件写入的onPictureTaken.您要做的就是将文件输出流更改为所需的文件名.
This was resolved by implementing PictureCallback via a ImageCaptureCallback class, and Overriding the onPictureTaken where the file was being written via a file output stream. All you had to do was change the fileoutput stream to the filename you want.
这篇关于Android:从相机获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!