2009-05-04 63 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