0

这里的代码工作正常,除了 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

但我不知道如何取消翻转图像。

4

2 回答 2

0

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

于 2009-05-04T04:39:26.233 回答
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
于 2009-05-04T06:35:12.523 回答