0

In the answer of the question getPublicStorage(“Pictures”) lists no files we have tried solution 1 and 2 but in the byte array process seems the array does not represent the actual image.

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)

Any idea for a fix \ tweak \ workaround would be much appreciated.

Community
  • 1
  • 1
  • Post what you have tried, so it can be reproduced, and what doesn't work for you. Do you get a picture even if it is not the same? – José Pereda Apr 29 '17 at 19:33
  • Hello Jose, the code you used was [link](https://pastebin.com/0e20kzBE) Trying to make the code block between // text in the ImageView is white because An exception is given [link](https://pastebin.com/e7FeCdER) ImageViewDialog.java:260 -> Image image2 = new Image(in); Thanks for your attention – Wilbert Marcia Apr 29 '17 at 20:28
  • You should edit the question, and add the relevant code and exceptions to it. Anyway, note that you can't create an `Image` from the raw pixels. If you just want to test it, use a `PixelWriter` like I showed in my answer. – José Pereda Apr 29 '17 at 23:12
  • JavaFx solution ->[here](http://stackoverflow.com/questions/24038524/how-to-get-byte-from-javafx-imageview). Just scroll down. – SedJ601 Apr 29 '17 at 23:36
  • Thanks Jose for your comments – Wilbert Marcia May 03 '17 at 16:19

0 Answers0