2

我使用这个库github:gphoto2-jna来访问我的尼康。我得到了预览工作(实时预览并将预览图像保存到磁盘),但我陷入了捕捉普通照片并将其保存到磁盘的困境。我认为我的问题只是一个指针问题,但是由于我没有使用这些东西,所以我很难弄清楚这个问题:D

这是我制作的代码:

public void takePhoto() {
 CameraFilePath captureImage = captureImage(_camera, _context);
 PointerByReference pbRef = new PointerByReference(captureImage.getPointer());
 byte[] cameraFileData = getCameraFileData(pbRef, _camera, _context); //from demo
 BufferedImage image = ImageIO.read(new ByteArrayInputStream(cameraFileData));
 //write image to disk
}

public static PointerByReference captureImage(Camera camera, PointerByReference context) {
 CameraFilePath.ByReference cameraPath = new CameraFilePath.ByReference();
 PointerByReference pbRef = new PointerByReference(cameraPath.getPointer());
 {
   check(Gphoto2Library.INSTANCE.gp_file_new(pbRef));
   pbRef.setPointer(pbRef.getValue());
 }
 synchronized (LOCK_OBJECT_CAPTURE) {
   check(Gphoto2Library.INSTANCE.gp_camera_capture(camera, 0, cameraPath, context));
 }
 return cameraPath;
}

public static byte[] getCameraFileData(PointerByReference cameraFile, Camera camera, PointerByReference context) {
 PointerByReference pref = new PointerByReference();
 LongByReference longByRef = new LongByReference();
 int captureRes = check(Gphoto2Library.INSTANCE.gp_file_get_data_and_size(cameraFile, pref, longByRef));
    if (captureRes >= 0) {
        // throws NullPointer
        return pref.getValue().getByteArray(0, (int) longByRef.getValue());
    } else {
        return null;
    }
}

如果您知道如何解决此问题,请告诉我。提前致谢!

4

0 回答 0