Hello Bill,
Quote
> Having a similiar problem
> My error is
> Project Project1.exe raised exception class EAccessViolation with
> message 'Access violation at address 004016FD. Read of address
> 82C5F001'. Process stopped. Use Step or Run to continue.
Hmm, an overrun of the array bounds in this case I suspect<g>
Let's go through your code step by step.
[ snip ]
Quote
> struct testpixel
> {
> Byte Red;
> Byte Green;
> Byte Blue;
> };
Well I would opt for using RGBTRIPLE as provided by the winapi, but if you
really want to use your own structure for this, the above is the first cause
for your problems. In bcb(version 4) internal data storage is 4 byte
aligned, what means that the above struct will not have the sizeof of 24
bits like you would expect. You can remedy this by using #pragma directives.
Rewrite the above struct as follows:
#pragma push(pack, 1) // set to 1 byte alignment
typedef struct tag_testpixel {
Byte Red, Green, Blue;
Quote
} testpixel, *ptestpixel;
#pragma push(pop) // reset to previous alignment value
[ snip ]
Quote
> byte* linePtr,*pixelPtr;
Although you could traverse the *LinePtr in steps of three for each RGB
color you would make it much easier on yourself to use a 24 bits struct like
you've just created<g> so do:
ptestpixel LinePtr;
Quote
> int numberPix = pBitmap->Height * pBitmap->Width;
> testpixel *pixel = new testpixel [numberPix];
So far so good, now do the following
int w = pBitmap->Width;
for (int y = 0; y < pBitmap->Height; y++) {
linePtr = (ptestpixel)pBitmap->ScanLine[y];
for (int x = 0; x < pBitmap->Width; x++) {
// btw writing to file can be done more easy by LinePtr directly
pixel[w*y+x]= LinePtr[x];
fprintf(outfile, " %d R",pixel[w*y+x].Red);
fprintf(outfile, " %d G",pixel[w*y+x].Green);
fprintf(outfile, " %d B",pixel[w*y+x].Blue);
fprintf(outfile, " - ");
}
}
Quote
> fprintf(outfile, "Done");
> fclose(outfile);
Don't forget to delete[] pixel; here to prevent memory leaks...
However, if you just want to write the pixel values directly to a file you
can ommit the whole testpixel *pixel all together and use the LinePtr in
fprintf instead.
Note I have not tested the above but, in principle, the code should work
now.
Hope this helped somewhat...;-))
Greetings from overcast Amsterdam
Jan
email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster