Error Syntax Question

Asked 2 years ago, Updated 2 years ago, 73 views

java.lang.ArrayIndexOutOfBoundsException: 700 at java.awt.image.BufferedImage.setRGB(Unknown Source) at com.wein.wincos.cc.ImageUtill.resize(ImageUtill.java:70) at com.wein.wincos.cc.convContCtl.photoSend(convContCtl.java:200) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)

If you look at the actual code, there's an error try { pg.grabPixels(); //Run Shrink Image } } catch (Exception e) { throw new IOException(e.getMessage()); } BufferedImage destImg = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); destImg.setRGB(0, 0, destWidth, destHeight, pixels, 0, destWidth); //The image you read ImageIO.write(destImg, "jpg", dest); //Thumbnail image.Create a file in jpg format. }

I think it's this part, but I don't know why, so if you want to answer, please answer.

java spring

2022-09-22 21:42

1 Answers

Reorganize the contents.

In the declaration of a two-dimensional data array, width and height are incorrectly described as plus (+), not multiplied by (*).

The summary is as follows:

int pixels[] = new int[destWidth+destHeight]; //pixel is a two-dimensional data array, described as plus (+), not multiplication (*)

destImg.setRGB(0,0, 0, destWidth, destHeight, pixels, 0, destWidth); // ArrayIndexOutOfBounds error due to mismatch between pixels size and destWidth, destHeight

the last reply

Out Of Bounds error.

In other words, if I approach the area where the allocated array range is filled, I am an error.

For example, int i[100], which is an error that occurs when i[101] is approached together.

Look at the size of the array and where the error occurred.


2022-09-22 21:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.