私はプログラミングに慣れていません。現在、画像を右回転と逆回転させるプログラムを作成中です。私は逆さまの方法を働かせることができましたが、右回り(時計回りに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