我必須得到的值,我必須匹配我的圖像中的像素值。但是當我運行這個代碼時,我得到StackOverflowError
。當我運行此代碼時,出現stackoverflow錯誤
如何在java中增加棧內存來克服這個問題。
public class ImageToText {
private final int ALPHA = 24;
private final int RED = 16;
private final int GREEN = 8;
private final int BLUE = 0;
public static void main(String args[]) throws IOException {
File file = new File("C:\\image.jpg");
BufferedImage image = ImageIO.read(file);
int color21=image.getHeight();
int color31=image.getWidth();
getRGBA(image,color31,color21);
for (int i = 0; i < image.getHeight(); i++)
{
for (int j = 0; j < image.getWidth(); j++)
{
int color = image.getRGB(j, i);
int color2=image.getHeight();
int color3=image.getWidth();
System.out.println(color2);
}
}
}
public static int[] getRGBA(BufferedImage img, int x, int y)
{
int[] color = new int[4];
int[] originalPixel = getRGBA(img,x,y);
for (int i=0;i<img.getWidth();i++)
{
for (int j=0;j<img.getHeight();j++)
{
int[] color1 = getRGBA(img,i,j);
if (originalPixel[0] == color1[0] && originalPixel[1] == color1[1] && originalPixel[2] == color1[2] && originalPixel[3] == color1[3])
{
img.setRGB(i, j,Color.red.getRGB());
}
else
{
img.setRGB(i, j,Color.yellow.getRGB());
}
}
}
return color;
}
}
如何克服此錯誤?
顯示錯誤堆棧跟蹤PLS – PSR
'公共靜態INT [] getRGBA(BufferedImage的IMG,INT的x,int y)對 { INT []顏色=新INT [4]; int [] originalPixel = getRGBA(img,x,y);'這將永遠循環。你必須找到另一種做你想做的事情的方式。 – Nbr44
我想克服這個錯誤以及如何解決這個問題。我必須匹配像素,如果像素值匹配,我會更改像素值。 –