2009-05-04 55 views
0

我的代码here工作正常,除了所有的2个图像的非功率翻转y方向。在wxImageLoader文件中有这样的循环,我认为是罪魁祸首:Unflip wxImage loading

for(int y=0; y<newHeight; y++) 
    { 
     for(int x=0; x<newWidth; x++) 
     { 

      if(x<(*imageWidth) && y<(*imageHeight)){ 
       imageData[(x+y*newWidth)*bytesPerPixel+0]= 
       bitmapData[(x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 0]; 

       imageData[(x+y*newWidth)*bytesPerPixel+1]= 
        bitmapData[(x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 1]; 

       imageData[(x+y*newWidth)*bytesPerPixel+2]= 
        bitmapData[(x+(rev_val-y)*(*imageWidth))*old_bytesPerPixel + 2]; 

       if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3]= 
        alphaData[ x+(rev_val-y)*(*imageWidth) ]; 

      } 
      else 
      { 

       imageData[(x+y*newWidth)*bytesPerPixel+0] = 0; 
       imageData[(x+y*newWidth)*bytesPerPixel+1] = 0; 
       imageData[(x+y*newWidth)*bytesPerPixel+2] = 0; 
       if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3] = 0; 
      } 

     }//next 
    }//next 

但我无法弄清楚如何取消翻转图像。

回答

0

正确的for循环:

for(int y=0; y<newHeight; y++) 
    { 
     for(int x=0; x<newWidth; x++) 
     { 

      if(x<(*imageWidth) && y<(*imageHeight)){ 
       imageData[(x+y*newWidth)*bytesPerPixel+0]= 
       bitmapData[(x+y*(*imageWidth))*old_bytesPerPixel + 0]; 

       imageData[(x+y*newWidth)*bytesPerPixel+1]= 
        bitmapData[(x+y*(*imageWidth))*old_bytesPerPixel + 1]; 

       imageData[(x+y*newWidth)*bytesPerPixel+2]= 
        bitmapData[(x+y*(*imageWidth))*old_bytesPerPixel + 2]; 

       if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3]= 
        alphaData[ x+y*(*imageWidth) ]; 

      } 
      else 
      { 

       imageData[(x+y*newWidth)*bytesPerPixel+0] = 0; 
       imageData[(x+y*newWidth)*bytesPerPixel+1] = 0; 
       imageData[(x+y*newWidth)*bytesPerPixel+2] = 0; 
       if(bytesPerPixel==4) imageData[(x+y*newWidth)*bytesPerPixel+3] = 0; 
      } 

     }//next 
    }//next 
0

在循环中,您使用(rev_val - y)作为“旧”图像像素的索引。这将导致图像翻转。尝试寻找替代品。从你发布的代码中很难知道rev_val的功能是什么。

+0

完整代码是在我张贴的问题 – DShook 2009-05-04 04:50:48

+0

OK的链接。我错过了。代码故意翻转图像。但它似乎也为两张图片的功率做了同样的事情。试着用y代替rev_val-y来调试它,看看会发生什么。 – 2009-05-04 06:30:17