Java镜像对角线方法不起作用
我很难让我的方法发挥作用。该方法应该镜像我在对角线上选择的任何图像以产生镜像效果,但目前它只生成未编辑的相同图像,我不知道我做错了什么。任何帮助都将不胜感激。多谢各位Java镜像对角线方法不起作用,java,Java,我很难让我的方法发挥作用。该方法应该镜像我在对角线上选择的任何图像以产生镜像效果,但目前它只生成未编辑的相同图像,我不知道我做错了什么。任何帮助都将不胜感激。多谢各位 public Picture mirrorImageDiagonal() { int size = this.getWidth(); Pixel rightPixel = null; Pixel leftTargetPixel = null; Pixel rightTargetPixel = null; Pic
public Picture mirrorImageDiagonal() {
int size = this.getWidth();
Pixel rightPixel = null;
Pixel leftTargetPixel = null;
Pixel rightTargetPixel = null;
Picture target = new Picture(size, size);
for (double x = 0; x < size; x ++) {
for (double y = 0; y <= x; y ++) {
int yIndex = Math.min((int) y, this.getHeight() - 1);
int xIndex = Math.min((int) x, this.getWidth() - 1);
leftTargetPixel = target.getPixel(yIndex, xIndex);
rightTargetPixel = target.getPixel(xIndex, yIndex);
rightPixel = this.getPixel(xIndex, yIndex);
rightTargetPixel.setColor(rightPixel.getColor());
leftTargetPixel.setColor(rightPixel.getColor());
}
}
return target;
}
公共图片镜像镜像对角线(){
int size=this.getWidth();
Pixel rightPixel=null;
Pixel leftTargetPixel=null;
Pixel rightTargetPixel=null;
图片目标=新图片(大小、大小);
用于(双x=0;x 对于(double y=0;y我假设您正在尝试完成图片实验室数据包中A6的挑战。我刚刚为学校完成了此任务,但如果您没有完成,我希望这仍然对您有所帮助
public void mirrorDiagonal()
{
Pixel[][] pixels = this.getPixels2D();
Pixel pixel1 = null;
Pixel pixel2 = null;
int width = pixels[0].length;
for (int row = 0; row < pixels.length; row++)
{
for (int col = 0; col < width; col++)
{
if (col < pixels.length)
{
pixel1 = pixels[row][col];
pixel2 = pixels[col][row];
pixel1.setColor(pixel2.getColor());
}
}
}
}
public void mirror()
{
像素[][]像素=this.getPixels2D();
像素pixel1=零;
像素像素2=零;
整数宽度=像素[0]。长度;
对于(int row=0;row
leftTargetPixel.setColor(letPixel.getColor());从哪里获取Picture.java的id?