Domanda

Ho il codice qui che funziona benissimo tranne per il fatto che tutte le non-potenza di 2 immagini sono capovolte nella direzione y. Nel file wxImageLoader c'è questo loop che credo sia il colpevole:

    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

Ma non riesco a capire come annullare il capovolgimento delle immagini.

È stato utile?

Soluzione 2

Il ciclo for corretto è:

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

Altri suggerimenti

Nel tuo loop usi (rev_val - y) per l'indice dei pixel del tuo "vecchio" Immagine. Ciò causerà il capovolgimento dell'immagine. Prova a trovare un'alternativa. Dal tuo codice che hai pubblicato è difficile sapere quale sia la funzione di rev_val.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top