取消翻转wxImage加载

时间:2009-05-04 04:17:40

标签: c++ opengl wxwidgets

我让代码here正常工作,除了2个图像的所有非幂都在y方向上翻转。在wxImageLoader文件中有一个我认为是罪魁祸首的循环:

    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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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