在Java中获取BufferedImage部分时出错

时间:2023-02-10 00:25:46

Part of the program that I am creating requires that I ask the user for a character, convert it into a string, and then get individual sections of a buffered image, where the sections are the dimensions of the character/string.

我正在创建的程序的一部分要求我向用户询问一个字符,将其转换为字符串,然后获取缓冲图像的各个部分,其中部分是字符/字符串的尺寸。

However, the problem occurs when I try to go through the image section by section. The error occurs before the end of the first row of sections of the image, and it has to do with an out of bounds error, like the section of the buffered image I am requesting is outside of the actual dimensions of the buffered image I have.

但是,当我尝试逐段浏览图像时会出现问题。错误发生在图像的第一行部分结束之前,它与一个越界错误有关,就像我请求的缓冲图像的部分超出了我所拥有的缓冲图像的实际尺寸。

My Code:

for (int i = 0; i < bufferedimageHeight; i += characterHeight) {
  for(int j = 0; j < bufferedimageWidth; j += characterWidth) {
    if (myMethod(mybufferedimage.getSubimage(i, j, characterWidth, characterHeight))) {
      // TODO CODE HERE
    }
  }
}

Any help would be much appreciated.

任何帮助将非常感激。

1 个解决方案

#1


0  

Use:

for (int i = 0; i < bufferedimageHeight-characterHeight; i += characterHeight) {
  for(int j = 0; j < bufferedimageWidth-characterWidth; j += characterWidth)

#1


0  

Use:

for (int i = 0; i < bufferedimageHeight-characterHeight; i += characterHeight) {
  for(int j = 0; j < bufferedimageWidth-characterWidth; j += characterWidth)