本文介绍了正确的翻转/镜像的像素的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$



这两种类型的镜像的代码:

  void mirrorLeftRight()
{
for(int x = 0; x< width / 2; x ++){
for(int y = 0; y< height; y ++){
int temp = pixelData [x] [y];
pixelData [x] [y] = pixelData [width-x] [y]
pixelData [width-x] [y]
}
}
}

void mirrorUpDown()
{
for(int x = 0; x< width; x ++) {
for(int y = 0; y< height / 2; y ++){
int temp = pixelData [x] [y]
pixelData [x] [y] = pixelData [x] [height-y]
pixelData [x] [height-y]
}
}
}



对于翻转,只需使用 width height w / o除以2?

解决方案

上面的代码更像是正确的Flip, 。



镜像我猜你不能切换像素,而是从一边复制到另一边。



有了镜像我会猜测你需要改变

  int temp = pixelData [x] [y] 
pixelData [x] [y] = pixelData [width-x] [y]
pixelData [width-x] [y]
  pixelData [x] [y] = pixelData [width-x] [y] 


http://tinypic.com/r/fwubzc/5

That shows what a flip should be and what a mirror should be.

Code for both types of mirrors:

void mirrorLeftRight()
{
    for (int x = 0; x < width/2; x++) {
            for (int y = 0; y < height; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[width-x][y]
                pixelData[width-x][y]=temp;
            }
    }
}

void mirrorUpDown()
{
    for (int x = 0; x < width; x++) {
            for (int y = 0; y < height/2; y++) {
                int temp = pixelData[x][y];
                pixelData[x][y]=pixelData[x][height-y]
                pixelData[x][height-y]=temp;
            }
    }
}

Does this seem right for mirrors?

And for flip, just a matter of using width and height w/o dividing by 2?

解决方案

The code above seems more like the correct way to Flip, not mirror.

Mirror I would guess that you not switch the pixels, but rather copy from one side to the other.

With mirror I would guess that you need to change

int temp = pixelData[x][y];
pixelData[x][y]=pixelData[width-x][y]
pixelData[width-x][y]=temp;

to something like this only

pixelData[x][y]=pixelData[width-x][y]

这篇关于正确的翻转/镜像的像素的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:22