在问题getPublicStorage(“Pictures”) lists no files的答案中,我们尝试了解决方案1和2,但在字节数组过程中,似乎数组并不代表实际图像。
Used code:
Services.get(PicturesService.class).ifPresent(service -> {
service.takePhoto(false).ifPresent(image -> {
imageView.setImage(image);
PixelReader pixelReader = image.getPixelReader();
int width = (int) image.getWidth();
int height = (int) image.getHeight();
byte[] buffer = new byte[width * height * 4];
pixelReader.getPixels(0, 0, width, height, PixelFormat.getByteBgraInstance(), buffer, 0, width * 4);
//Test
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
Image image2 = new Image(in);
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
imageView.setImage(image2);
//Test
proceedImage(buffer);
});
});
private void proceedImage(byte[] arrayImage) {
this.arrayImage = arrayImage;
enableZoom(true);
apply = true;
}
Exception:
W/System.err(15096): com.sun.javafx.iio.ImageStorageException: No loader for image data
W/System.err(15096): at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:276)
W/System.err(15096): at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:142)
W/System.err(15096): at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:77)
W/System.err(15096): at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:740)
W/System.err(15096): at javafx.scene.image.Image.loadImage(Image.java:1073)
W/System.err(15096): at javafx.scene.image.Image.initialize(Image.java:804)
W/System.err(15096): at javafx.scene.image.Image.<init>(Image.java:707)
W/System.err(15096): at org.openjanela.dialog.ImageViewDialog.lambda$null$5(ImageViewDialog.java:260)
非常感谢修复\ tweak \ workaround的任何想法。