首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何水平镜像镜像?

如何水平镜像镜像?
EN

Stack Overflow用户
提问于 2015-03-23 09:37:19
回答 1查看 722关注 0票数 0

我是一个高中生。我想水平镜像一个图像。我已经想出了垂直镜像的方法,但我不知道如何开始这项任务。

我复制并粘贴了前面方法中的代码,正在寻找要编辑的东西,但到目前为止还没有成功。

代码语言:javascript
复制
public void mirrorHorizontal()
  {
      Pixel[][] pixels = this.getPixels2D();
      Pixel leftPixel = null;
      Pixel rightPixel = null;
      int width = pixels[0].length;
      for (int row = 0; row < pixels.length; row++)
      {
         for (int col = 0; col < width / 2; col++)
         {
            leftPixel = pixels[row][col];
            rightPixel = pixels[row][width - 1 - col];
            leftPixel.setColor(rightPixel.getColor());
         }
      }
  }

如何更改此代码以水平镜像图像?

EN

回答 1

Stack Overflow用户

发布于 2015-03-23 10:32:33

这样做了吗?

代码语言:javascript
复制
public void mirrorHorizontal()
      {
          Pixel[][] pixels = this.getPixels2D();
          Pixel topPixel = null;
          Pixel bottomPixel = null;

      int height = pixels.length;
      int width = pixels[0].length;

      for (int row = 0; row < height / 2; row++)
      {
         for (int col = 0; col < width; col++)
         {
            topPixel = pixels[row][col];
            bottomPixel = pixels[height - 1 - row][width];
            topPixel.setColor(bottomPixel.getColor());
         }
      }
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29202063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档