hi, how to read bits from CImage class

B

Baby Lion

I use the getbits like this ,but when I read half of the image ,the
error occur, could you tell me why this happen , and do I need to lock
the memory of CImage.GetBits() before I use it,

thanks


w = image.GetWidth();
h = image.GetHeight();
int nClrCount = image.GetBPP()/8;
BYTE * pImageData = (BYTE *)image.GetBits(); ///??? do I need to lock
it ? and how to lock it?
int Pitch = image.GetPitch();

if( nClrCount == 3)
{

for( int y = 0; y<h ; y++)
{
for( int x = 0 ;x<w; x++)
{
WORD hue,luminance,saturation;
BYTE bRed,bGreen,bBlue;
BYTE * p = pImageData + (y*w+x)*3; //////?????right?
/// the runtime error
happened here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
bRed = *p;
bGreen = *(p+1);
bBlue = * (p+2);
COLORREF color = RGB(bRed, bGreen, bBlue);
ColorRGBToHLS(color,&hue,&luminance,&saturation);
if( luminance > 240)
{
cout<<"ERROR: luminance>240"<<endl;
throw exception();
}
if( Pitch < 0 )
{
PgmM[h-y-1][x] = luminance /240.0;
}else{
PgmM[y][x] = luminance / 240.0;
}

}
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top