|
From: RAN on 16 May 2008 16:34 Hello, I have loaded a bitmap resource using: .. .. .. po_StartBitmap[6] =(BYTE*) LockResource(LoadResource(NULL,FindResource(NULL,MAKEINTRESOURCE(IDB_WHITEPAWN),RT_BITMAP))); I probably should have done this using GetDIBits() but i could not get it to work just now, so i tried this instead. It does what i want, getting a pointer to the bitmapdata, may try GetDIBits() later. I want to draw the bitmap in OnDraw() using SetPixel(). Like so: void CPGNFENEditorView::Draw_WhitePawn(int n_X, int n_Y, CDC *po_dc) { BYTE* po_Bitmap; po_Bitmap = po_StartBitmap[6]; int nWidth =55; int nHeight =64; int nX,nY; po_Bitmap+=40; // start pixeldata for(nY = 0; nY < nHeight; nY ++) { for(nX = 0; nX < nWidth; nX++) { if( *(po_Bitmap ) != 0xff || *(po_Bitmap + 1) != 0xff || *(po_Bitmap + 2) != 0xff) po_dc->SetPixel (n_X+nX,n_Y+nY,RGB(*(po_Bitmap),*(po_Bitmap +1),*(po_Bitmap+2))); po_Bitmap+=3; } po_Bitmap+=3; // skip trailing zeros for multiples of four. } } I have a bitmap with a black king (chesspiece) which is black, this bitmap is drawn perfectly using the SetPixel() code. (Its black and the shape is what it should be) Then i have a bitmap with a white king which is actually yellow in color. The above code displayes the bitmap perfectly, BUT its not yellow but blue! How can the bitmap be displayed perfectly but be of a different color than it originally is?
From: Joseph M. Newcomer on 16 May 2008 17:35 See below... On Fri, 16 May 2008 13:34:39 -0700 (PDT), RAN <nijenhuis(a)wish.nl> wrote: >Hello, > >I have loaded a bitmap resource using: >. >. >. > po_StartBitmap[6] =(BYTE*) >LockResource(LoadResource(NULL,FindResource(NULL,MAKEINTRESOURCE(IDB_WHITEPAWN),RT_BITMAP))); **** These operations should not be compounded like this. You have no idea if any of these succeed. **** > >I probably should have done this using GetDIBits() but i could not get >it to work just now, so i tried this instead. >It does what i want, getting a pointer to the bitmapdata, may try >GetDIBits() later. > >I want to draw the bitmap in OnDraw() using SetPixel(). >Like so: >void CPGNFENEditorView::Draw_WhitePawn(int n_X, int n_Y, CDC *po_dc) >{ > > BYTE* po_Bitmap; > > po_Bitmap = po_StartBitmap[6]; **** I note that you did not tell us what the declaration of po_StartBitmap is; how are we to make sense of this assignment? **** > > int nWidth =55; > int nHeight =64; > int nX,nY; **** Do not use commas in declaration lists, and if you feel you have to, remember to use whitespace to make code readable. **** > > po_Bitmap+=40; // start pixeldata > for(nY = 0; nY < nHeight; nY ++) ***** How do you know it is 40? Where did this number come from? Why should we believe it? Did not not mean sizeof() of some well-defined structure? **** > { > for(nX = 0; nX < nWidth; nX++) > { > if( *(po_Bitmap ) != 0xff || *(po_Bitmap + 1) != 0xff || >*(po_Bitmap + 2) != 0xff) > po_dc->SetPixel (n_X+nX,n_Y+nY,RGB(*(po_Bitmap),*(po_Bitmap >+1),*(po_Bitmap+2))); > po_Bitmap+=3; > } > po_Bitmap+=3; // skip trailing zeros for multiples of four. > } >} **** This loop is about the clumsiest thing I've seen in a long time. Why not BitBlt? If you need something that is transparent, create two bitmaps: a mask bitmap and a data bitmap, and do two BitBlts, one which ANDs the mask (black where you want color, white where you want background) and ORs the data (black where you want transparency). The GetDIBits is irrelevant here. You've been going after the wrong solution. **** > >I have a bitmap with a black king (chesspiece) which is black, this >bitmap is drawn perfectly using the SetPixel() code. (Its black and >the shape is what it should be) >Then i have a bitmap with a white king which is actually yellow in >color. >The above code displayes the bitmap perfectly, BUT its not yellow but >blue! **** Blue is the complement of yellow. That should suggest something.But I think the correct answer is not to fix this code, but to write better code that involves no loops at all. joe **** >How can the bitmap be displayed perfectly but be of a different color >than it originally is? > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: RAN on 16 May 2008 18:06 On 16 mei, 23:35, Joseph M. Newcomer <newco...(a)flounder.com> wrote: > See below... > > On Fri, 16 May 2008 13:34:39 -0700 (PDT), RAN <nijenh...(a)wish.nl> wrote: > >Hello, > > >I have loaded a bitmap resource using: > >. > >. > >. > > po_StartBitmap[6] =(BYTE*) > >LockResource(LoadResource(NULL,FindResource(NULL,MAKEINTRESOURCE(IDB_WHITEPAWN),RT_BITMAP))); > > **** > These operations should not be compounded like this. You have no idea if any of these > succeed. > **** > > >I probably should have done this using GetDIBits() but i could not get > >it to work just now, so i tried this instead. > >It does what i want, getting a pointer to the bitmapdata, may try > >GetDIBits() later. > > >I want to draw the bitmap in OnDraw() using SetPixel(). > >Like so: > >void CPGNFENEditorView::Draw_WhitePawn(int n_X, int n_Y, CDC *po_dc) > >{ > > > BYTE* po_Bitmap; > > > po_Bitmap = po_StartBitmap[6]; > > **** > I note that you did not tell us what the declaration of po_StartBitmap is; how are we to > make sense of this assignment? > **** > > > int nWidth =55; > > int nHeight =64; > > int nX,nY; > > **** > Do not use commas in declaration lists, and if you feel you have to, remember to use > whitespace to make code readable. > **** > > > po_Bitmap+=40; // start pixeldata > > for(nY = 0; nY < nHeight; nY ++) > > ***** > How do you know it is 40? Where did this number come from? Why should we believe it? Did > not not mean sizeof() of some well-defined structure? > ****> { > > for(nX = 0; nX < nWidth; nX++) > > { > > if( *(po_Bitmap ) != 0xff || *(po_Bitmap + 1) != 0xff || > >*(po_Bitmap + 2) != 0xff) > > po_dc->SetPixel (n_X+nX,n_Y+nY,RGB(*(po_Bitmap),*(po_Bitmap > >+1),*(po_Bitmap+2))); > > po_Bitmap+=3; > > } > > po_Bitmap+=3; // skip trailing zeros for multiples of four. > > } > >} > > **** > This loop is about the clumsiest thing I've seen in a long time. Why not BitBlt? If you > need something that is transparent, create two bitmaps: a mask bitmap and a data bitmap, > and do two BitBlts, one which ANDs the mask (black where you want color, white where you > want background) and ORs the data (black where you want transparency). The GetDIBits is > irrelevant here. You've been going after the wrong solution. > **** > > >I have a bitmap with a black king (chesspiece) which is black, this > >bitmap is drawn perfectly using the SetPixel() code. (Its black and > >the shape is what it should be) > >Then i have a bitmap with a white king which is actually yellow in > >color. > >The above code displayes the bitmap perfectly, BUT its not yellow but > >blue! > > **** > Blue is the complement of yellow. That should suggest something.But I think the correct > answer is not to fix this code, but to write better code that involves no loops at all. > joe > > ****>How can the bitmap be displayed perfectly but be of a different color > >than it originally is? > > Joseph M. Newcomer [MVP] > email: newco...(a)flounder.com > Web:http://www.flounder.com > MVP Tips:http://www.flounder.com/mvp_tips.htm Thanks! I think i found a sample on the net about this technique.
|
Pages: 1 Prev: Selecting display in dual monitor system Next: Calculation mystery |