Question

J'ai le code ici fonctionne correctement, sauf que toutes les images non puissantes de 2 images sont inversées dans la direction y. Dans le fichier wxImageLoader, il y a cette boucle dont je crois être le coupable:

    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

Mais je n'arrive pas à comprendre comment annuler les images.

Était-ce utile?

La solution 2

La boucle correcte pour est:

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

Autres conseils

Dans votre boucle, vous utilisez (rev_val - y) pour l’index des pixels de votre " ancien " image. Cela fera basculer l'image. Essayez de trouver une alternative. À partir de votre code, il est difficile de savoir quelle est la fonction de rev_val.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top