【发布时间】:2016-04-28 21:42:09
【问题描述】:
我的目标是在相机预览上添加一个覆盖,以便找到书本边缘。为此,我在执行以下操作时覆盖了 onPreviewFrame:
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
int width = parameters.getPreviewSize().width;
int height = parameters.getPreviewSize().height;
Mat mat = new Mat((int) (height*1.5), width, CvType.CV_8UC1);
mat.put(0,0,data);
byte[] bytes = new byte[(int) (height*width*1.5)];
mat.get(0,0,bytes);
if (!test) { //to only do once
File pictureFile = getOutputMediaFile();
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(bytes);
fos.close();
Uri picUri = Uri.fromFile(pictureFile);
updateGallery(picUri);
test = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
现在我只想获取其中一个预览并在转换为 mat 后将其保存。
花了无数个小时使上面看起来正确后,在我的测试手机(LG Leon)上看不到保存的图片。我似乎找不到问题。我是不是因为我在纵向模式下拍照而混合了高度/宽度?我尝试切换它们,但仍然无法正常工作。问题出在哪里?
【问题讨论】: