Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Image topics

Status
Not open for further replies.

cyprus106

Programmer
Apr 30, 2001
654
I've got 2 questions, actually...
The first:
the code below is supposed to invert the colors of an entire image. Unfortunately, it usually only inverts about 1/3 of the way over and then stops. I think the only time it totally inverts is on a 256x256 image. I'm almost positive this occurs because when the width is larger than the height. I think it stops because it only scanlines as far as the height and the width statement is inside of that so thats when it stops. But I've tried all sizes of images and its always the same thing. I think it would probably be best if you copied and pasted the code and looked for yourself. It's confusing to explain.

int x, y;
BYTE* LinePtr;

/* inversion */
for (y = 0; y < Image1->Height; y++)
{
LinePtr = (BYTE*)Image1->Picture->Bitmap->ScanLine[y];

for (x = 0; x < Image1->Width; x++)
LinePtr[x] = 255 - LinePtr[x];
}

Image1->Refresh();

I hope someone who knows more about math and logic than me can work this out. I KNOW it's got to be something simple but I'm out of options.



The second question>
Does anybody have any good websites on advanced image topics and BCB? Any image topics for that matter...


Thanks, Cyprus
 
1: An picture can stretch in the image control
Better to take the Image1->Picture->Width instead of Image1->Width

2: When using a byte pointer with a color depth of 24 bits, multiply the width by 3

this should work:
int x, y, w;
BYTE* LinePtr;

/* inversion */
if( Image1->Picture->Bitmap->PixelFormat == pf8bit ) {
w = Image1->Picture->Width;
}
if( Image1->Picture->Bitmap->PixelFormat == pf16bit ) {
w = Image1->Picture->Width*2;
}
if( Image1->Picture->Bitmap->PixelFormat == pf24bit ) {
w = Image1->Picture->Width*3;
}
for (y = 0; y < Image1->Picture->Height; y++) {
LinePtr = (BYTE*)Image1->Picture->Bitmap->ScanLine[y];
for (x = 0; x < w; x++)
LinePtr[x] = 255 - LinePtr[x];
}
Image1->Refresh();
 
Hey, it worked! thanks a lot! That was driving me crazy. Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top