Вопрос

Well, the title is pretty self-explanatory. I have tested this code thoroughly, and what I have found is that the code is somehow resetting "y" when getPixel is called. It shouldn't be possible you'd think, because the method doesn't take a pointer, but somehow that is what's happening. If I remove the line of code that calls getPixel, the code completes, although obviously nothing useful is produced. If anyone can figure out what's going on here, I would be most appreciative. (getPixel is in NSBitmapImageRep, FYI)

NSInteger pixWide = theCAPTCHA.pixelsWide;
NSInteger pixHigh = theCAPTCHA.pixelsHigh;
for (NSInteger x = 0; x<pixWide;x++)
{
    for (NSInteger y = 0; y<pixHigh;y++)
    {
        unsigned int thePixel[3];
        [theCAPTCHA getPixel:(unsigned long *)thePixel atX:x y:y];
        for (int i = 0; i<3; i++) {
            theColors[i+(y*3)+(x*pixHigh)] = thePixel[i];
        }
    }
}
Это было полезно?

Решение

thePixel is an unsigned int but passed in as unsigned long. The function might be overflowing your integer and changing y. Try declaring thePixel as unsigned long

In memory, the variables are just laid out one after another. The function getPixel:at:y: assumes it has 64 bits to write to in the input, because it takes an unsigned long *. However your own variable thePixel is an unsigned int * and writing an unsigned long to it will cause an overflow in memory

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top