Pregunta

Tengo el código aquí funcionando bien, excepto que todo el poder de 2 imágenes no se ha volteado en la direccion y En el archivo wxImageLoader hay un bucle que creo que es el culpable:

    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

Pero no puedo descubrir cómo deshacer las imágenes.

¿Fue útil?

Solución 2

El bucle for correcto es:

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

Otros consejos

En tu bucle usas (rev_val - y) para el índice de los píxeles de tu " antiguo " imagen. Esto hará que la imagen se invierta. Trate de encontrar una alternativa. Desde su código publicado, es difícil saber cuál es la función de rev_val.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top