在Java中重复一个方法? /旋转图片

时间:2013-11-12 19:17:49

标签: java image rotation

我有一种方法可以将图片旋转90度,但我需要单独写一个旋转180度,另一个旋转270度。我想我可以通过重复90度的方式来做到这一点,但我是新手并且不知道。

我的90度代码:

    public Picture rotateRight90()
  {
   Picture rotated = new Picture (getHeight(), getWidth());

   for (int x = 0, roty = 0; x < getWidth(); x++, roty++)
   {
    for ( int y = 0, rotx = getHeight() - 1; y < getHeight(); y++, rotx--)
    {
       Pixel orig = getPixel(x,y);
       Pixel rotPix = rotated.getPixel (rotx, roty);
       rotPix.setColor(orig.getColor());
    }
   }
   return rotated;
  }

我尝试轮换180代码:

     public Picture rotate180()
 {
   Picture rotated = new Picture (getHeight(), getWidth());

   for (int z = 0; z < 2; z++)
   {
     for (int x = 0, roty = 0; x < getWidth(); x++, roty++)
   {
    for ( int y = 0, rotx = getHeight() - 1; y < getHeight(); y++, rotx--)
    {
       Pixel orig = getPixel(x,y);
       Pixel rotPix = rotated.getPixel (rotx, roty);
       rotPix.setColor(orig.getColor());
    }
   }
   }
   return rotated;
  }

0 个答案:

没有答案