mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
support camera zoom during capture with mouse scroll
This commit is contained in:
parent
6f6d61fb75
commit
f1c4b8aa69
2 changed files with 48 additions and 4 deletions
|
|
@ -15,10 +15,7 @@ import javafx.concurrent.Task;
|
|||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.image.Image;
|
||||
import net.sourceforge.zbar.ZBar;
|
||||
import org.openpnp.capture.CaptureDevice;
|
||||
import org.openpnp.capture.CaptureFormat;
|
||||
import org.openpnp.capture.CaptureStream;
|
||||
import org.openpnp.capture.OpenPnpCapture;
|
||||
import org.openpnp.capture.*;
|
||||
import org.openpnp.capture.library.OpenpnpCaptureLibrary;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -50,6 +47,7 @@ public class WebcamService extends ScheduledService<Image> {
|
|||
|
||||
private final OpenPnpCapture capture;
|
||||
private CaptureStream stream;
|
||||
private PropertyLimits zoomLimits;
|
||||
private long lastQrSampleTime;
|
||||
private final Reader qrReader;
|
||||
private final Bokmakierie bokmakierie;
|
||||
|
|
@ -151,6 +149,12 @@ public class WebcamService extends ScheduledService<Image> {
|
|||
stream = device.openStream(format);
|
||||
opening.set(false);
|
||||
closed.set(false);
|
||||
|
||||
try {
|
||||
zoomLimits = stream.getPropertyLimits(CaptureProperty.Zoom);
|
||||
} catch(Throwable e) {
|
||||
log.debug("Error getting zoom limits on " + device + ", assuming no zoom function");
|
||||
}
|
||||
}
|
||||
|
||||
BufferedImage originalImage = stream.capture();
|
||||
|
|
@ -177,6 +181,7 @@ public class WebcamService extends ScheduledService<Image> {
|
|||
@Override
|
||||
public void reset() {
|
||||
stream = null;
|
||||
zoomLimits = null;
|
||||
super.reset();
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +199,32 @@ public class WebcamService extends ScheduledService<Image> {
|
|||
capture.close();
|
||||
}
|
||||
|
||||
public PropertyLimits getZoomLimits() {
|
||||
return zoomLimits;
|
||||
}
|
||||
|
||||
public int getZoom() {
|
||||
if(stream != null && zoomLimits != null) {
|
||||
try {
|
||||
return stream.getProperty(CaptureProperty.Zoom);
|
||||
} catch(Exception e) {
|
||||
log.error("Error getting zoom property on " + device, e);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setZoom(int value) {
|
||||
if(stream != null && zoomLimits != null) {
|
||||
try {
|
||||
stream.setProperty(CaptureProperty.Zoom, value);
|
||||
} catch(Exception e) {
|
||||
log.error("Error setting zoom property on " + device, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readQR(BufferedImage wideImage, BufferedImage croppedImage) {
|
||||
Result result = readQR(wideImage);
|
||||
if(result == null) {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,19 @@ public class WebcamView {
|
|||
imageView.setOnContextMenuRequested(event -> {
|
||||
contextMenu.show(imageView, event.getScreenX(), event.getScreenY());
|
||||
});
|
||||
imageView.setOnScroll(scrollEvent -> {
|
||||
if(service.isRunning() && scrollEvent.getDeltaY() != 0 && service.getZoomLimits() != null) {
|
||||
int currentZoom = service.getZoom();
|
||||
if(currentZoom >= 0) {
|
||||
int newZoom = scrollEvent.getDeltaY() > 0 ? Math.round(currentZoom * 1.1f) : Math.round(currentZoom * 0.9f);
|
||||
newZoom = Math.max(newZoom, service.getZoomLimits().getMin());
|
||||
newZoom = Math.min(newZoom, service.getZoomLimits().getMax());
|
||||
if(newZoom != currentZoom) {
|
||||
service.setZoom(newZoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
service.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if(newValue != null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue