image.flipHorizontally throws ArrayIndexOutOfBounds exception

43 views
Skip to first unread message

Carlos Verdier

unread,
May 13, 2021, 4:12:31 PM5/13/21
to CodenameOne Discussions
This is the output:

java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at java.desktop/sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:313)
at java.desktop/java.awt.image.BufferedImage.getRGB(BufferedImage.java:986)
at com.codename1.impl.javase.JavaSEPort.getRGB(JavaSEPort.java:5605)
at com.codename1.ui.Image.getRGB(Image.java:790)
at com.codename1.ui.EncodedImage.getRGB(EncodedImage.java:557)
at com.codename1.ui.Image.getRGBImpl(Image.java:865)
at com.codename1.ui.Image.getRGB(Image.java:824)
at com.codename1.impl.CodenameOneImplementation.flipImageHorizontally(CodenameOneImplementation.java:997)

Shai Almog

unread,
May 13, 2021, 11:38:46 PM5/13/21
to CodenameOne Discussions
What type of image are you trying to do this on?
How did you create the image object?
Can you attach it here?

Carlos Verdier

unread,
May 14, 2021, 7:44:32 AM5/14/21
to CodenameOne Discussions
EncodedImage imagenCargandoPortada = (EncodedImage) fetchResourceFile().getImage("magazineEscala.png");;
Image roundMask = Image.createImage(imagenCargandoPortada.getWidth(), imagenCargandoPortada.getHeight(), 0xff000000);
Graphics gr = roundMask.getGraphics();
gr.setColor(0xffffff);
gr.setAntiAliased(true);
gr.fillRoundRect(0, 0, imagenCargandoPortada.getWidth(), imagenCargandoPortada.getHeight(), 60, 60);
URLImage.ImageAdapter ada = URLImage.createMaskAdapter(roundMask);                                
URLImage imagen = URLImage.createToFileSystem(imagenCargandoPortada
         , directory
         , urlAdress
         , ada);
Image imgFlip = imagen.flipHorizontally(true);

Shai Almog

unread,
May 15, 2021, 1:44:30 AM5/15/21
to CodenameOne Discussions
I'm not sure why this will happen but the code has a problem either way.
flip will happen immediately and will lose the URLImage aspect of the image. So if the image isn't downloaded yet it will do it on the placeholder and the image won't download.
Would this exception happen if you do imagenCargandoPortada.flipHorizontally(true)?

Carlos Verdier

unread,
May 15, 2021, 7:01:13 AM5/15/21
to CodenameOne Discussions
Yes, that was the reason, thank you. It works now.
Reply all
Reply to author
Forward
0 new messages