题
我将代码此处正常工作,但所有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
正确的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
其他提示
在循环中,使用(rev_val - y)
作为“old”的像素索引。图片。这将导致图像翻转。尝试寻找替代方案。从你发布的代码中很难知道rev_val的功能是什么。
不隶属于 StackOverflow