프로그래밍에 익숙하지 않고 현재 이미지를 오른쪽 및 위 아래로 회전시키는 프로그램을 작성 중입니다. 나는 거꾸로 작동하는 방법을 얻을 수 있었지만 오른쪽으로 회전하지는 않았습니다 (시계 방향으로 90도 회전). 그것은 나에게 한계 밖의 오류를 계속주고, 나는 왜 내가 다른 예제들을 보았는지 확신 할 수 없다. 어떤 도움을 주시면 감사하겠습니다. 여기에 코드의 나머지 부분입니다스레드 "main"의 예외 java.lang.ArrayIndexOutOfBoundsException : 좌표 범위를 벗어남 setRGB
public Image rotateRight()
{
Image right = new Image (this);
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int width = right.img.getWidth();
int height = right.img.getHeight();
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
{
this.img.setRGB(height-j-1,i,right.img.getRGB(i,j));
}
return right;
}
: 여기
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
public class Image {
private BufferedImage img = null;
int width;
int height;
private Image()
{
}
public Image (int w, int h)
{
img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
width = w;
height = h;
}
public Image (Image anotherImg)
{
width = anotherImg.img.getWidth();
height = anotherImg.img.getHeight();
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
{
this.img.setRGB(j,i,anotherImg.img.getRGB(j,i)) ;
}
}
public String toString()
{
return "Width of Image:" +width+"\nHeight of Image:"+height;
}
public Image (String filename)
{
try
{
img = ImageIO.read(new File(filename));
width = img.getWidth();
height = img.getHeight();
}
catch (IOException e)
{
System.out.println(e);
}
}
public void save(String filename, String extension)
{
try
{
File outputfile = new File(filename);
ImageIO.write(img, extension, outputfile);
}
catch (IOException e)
{
System.out.println(e);
}
}
public Image copy()
{
Image copiedImage = new Image(this);
return copiedImage;
}
가의 주요 :
public static void main (String args[])
{
Image srcimg = new Image("apple.jpg");
System.out.println(srcimg);
Image copy = srcimg.copy();
copy.save("apple-copy.jpg", "jpg");
Image copy2 = srcimg.copy();
Image right = copy2.rotateRight();
right.save("apple-rotateRight.jpg", "jpg");
}
새 이미지 너비가 원본 높이와 같지 않아야합니까? ... img = new BufferedImage (height, width, BufferedImage.TYPE_INT_RGB); ... 또한 로컬 변수와 전역 변수에 같은 이름을 사용하고 있습니다. 조금 혼란 스럽습니다. – Plirkee
@Plirkee Woow .... 내 문제를 고쳤다. 지금 당장 화가났다. 문제가 for 루프에서 내 성명과 함께 있다고 생각했다.나는 너무 많은 시간을 낭비했고, 얼마 전에 여기에 올렸어야했다. .. 고맙습니다. D : 충고에 감사드립니다. – Alexis