Re: Signature control - 1 BPP bitmap

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am still having problems. When I execute the following code from within
my CWnd derived class:

CRect rDrawingSurface;
GetWindowRect(&rDrawingSurface);
ScreenToClient(&rDrawingSurface);
CBitmap ddbBitmap;
BOOL
bResult=ddbBitmap.CreateBitmap(rDrawingSurface.Width(),rDrawingSurface.Heigh
t(),1,1,NULL);
CDC dcMemDDB;
CDC *pDC=GetDC();
if (pDC)
{
if (dcMemDDB.CreateCompatibleDC(pDC))
{
CBitmap *pOldDDBBitmap=dcMemDDB.SelectObject(&ddbBitmap);

dcMemDDB.BitBlt(rDrawingSurface.left,rDrawingSurface.top,rDrawingSurface.Wid
th(),rDrawingSurface.Height(),pDC,0,0,SRCCOPY);
BITMAP bm;
::GetObject(ddbBitmap.GetSafeHandle(), sizeof(bm),(LPVOID)&bm);
}
}

When I look at bm.bmBits, it is NULL. If I try to do a dcMemDDB.GetPixel(),
they seem to all come out as 0. It seems like the BitBlt didn't work. What
am I missing? Thanks.

Timothy Dean

"Gary Daniels [MS]" <garydan@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:uwlI1y3xFHA.2932@xxxxxxxxxxxxxxxxxxxxxxx
> Blitting from a 1bpp surface interprets 0's as the background color and
1's
> as the foreground color on the destination surface, so if you blit a 1bpp
> bitmap to a 24bpp primary and the foreground/background colors are red and
> blue, then you'll see red and blue for the 1's/0's of the bitmap.
>
> What that means is blitting from a 1bpp bitmap to a 1bpp DIB results in a
> closest color match of the foreground/background colors to the DIB color
> table, not a direct copy of the 1's/0's. If you do a SetDIBColorTable on
the
> dib and set 1 to the foreground color and 0 to the background color then
the
> color conversion from the 1bpp DDB to the DIB should be what you expect.
>
> Gary Daniels
> Windows CE Multimedia and Graphics
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use.
>
> "Timothy Dean" <tim.dean@xxxxxxxxxxxxxxxxxxx> wrote in message
> news:uREkpdkxFHA.2652@xxxxxxxxxxxxxxxxxxxxxxx
> >I have tried this but apparently I must be doing something wrong. I need
> >to
> > eventually end up in a DIB section so I can store it as a device
> > independant
> > bitmap. So I tried BitBlt to a bitmap (device dependant) and then to a
1
> > bpp DIBSection from there. Maybe Blt-ing to the DIBSection is still
doing
> > the color matching, I don't know. How would I go from the bitmap to the
> > dibsection? Do I need to copy the bits direclty? Is there a code
example
> > I
> > could look at? Thanks.
> >
> > Timothy Dean
> >
> > "Gary Daniels [MS]" <garydan@xxxxxxxxxxxxxxxxxxxx> wrote in message
> > news:uaspUHixFHA.3740@xxxxxxxxxxxxxxxxxxxxxxx
> >> FYI, by 1bpp Bitmap, i'm referring to a bitmap created using
> >> CreateBitmap,
> >> not CreateDIBSection.
> >>
> >> Gary Daniels
> >> Windows CE Multimedia and Graphics
> >>
> >> This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> >> You assume all risk for your use.
> >>
> >> "Gary Daniels [MS]" <garydan@xxxxxxxxxxxxxxxxxxxx> wrote in message
> >> news:OirIHGixFHA.664@xxxxxxxxxxxxxxxxxxxxxxx
> >> > There's two behaviors for monochrome bitmaps. There's the DIB
behavior
> >> > where the closest match is picked (i don't remember the algorithm for
> > the
> >> > closest match), and then there's the 1bpp bitmap behavior where if
the
> >> > color matches the background color the pixel is 0, otherwise it's 1.
> >> > You
> >> > can either switch to using a 1bpp Bitmap, or you can adjust the DIB
> > color
> >> > table to get the results you want. If you adjust the DIB color table
> >> > and
> >> > blt from the dib back to a color surface you'll get the colors in the
> >> > color table for the pixels. You can always change the color table
after
> >> > you blt into the surface so the output is what you want though.
> >> >
> >> > I hope that helps,
> >> >
> >> > Gary Daniels
> >> > Windows CE Multimedia and Graphics
> >> >
> >> > This posting is provided "AS IS" with no warranties, and confers no
> >> > rights.
> >> > You assume all risk for your use.
> >> >
> >> >
> >> > "Timothy Dean" <tim.dean@xxxxxxxxxxxxxxxxxxx> wrote in message
> >> > news:e9H1EBixFHA.2232@xxxxxxxxxxxxxxxxxxxxxxx
> >> >> eVC++ 4.0 MFC
> >> >>
> >> >> I am trying to capture a window to a monochrome bitmap for a
signature
> >> >> control. When I BitBlt from the Windows DC into a 1 BPP DIBSection,
> >> >> it
> >> >> is
> >> >> doing color matching of the pixels instead of setting bits that
match
> > the
> >> >> background color to 0, and all others to 1. For example, if I set
the
> >> >> background color of the window to blue (RGB(0,0,255)) and set the
pen
> >> >> color
> >> >> to red (RGB(255,0,0)), when I BitBlt it to the monochrome
DIBSection,
> > all
> >> >> bits come out the same. I am assuming this is because both colors
are
> >> >> closer to black than white. If I set the pen color to white, it all
> >> >> comes
> >> >> out ok. Is there something I am doing wrong? Is there a good
sample
> >> >> that
> >> >> shows how to do this? Thanks.
> >> >>
> >> >> Timothy Dean
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>


.



Relevant Pages

  • Re: OLE-Typ mit VBA ermitteln
    ... diesem Thread zu sagen. ... dass der Inhalt eines OLE-Feldes etwas mit einem ... Ein DIB ist ein Bitmap. ...
    (microsoft.public.de.access)
  • Re: DIB vs. DIB
    ... So your statement "A HBITMAP is a handle to a device dependent bitmap" is as confused as me... ... A DIBSection is unique, because although it's a DIB, it has a HBITMAP so it can be used like a DDB in GDI functions. ... because the video device driver manages the bits of the bitmap - which is why all you get is a handle to the DDB. ... CreateBitmap really seems to be a holdover utility function from Win16 that sticks around because some people are too lazy to change to CreateCompatibleBitmap/CreateDIBitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: memory device context and DIB
    ... You may render to the offscreen DIB by using any of the GDI BitBlt ... nativeImage IntPtr is not zero, but the rawData bytemember is null. ... DIB, save the bitmap. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Signature control - 1 BPP bitmap
    ... Could this be affecting the initial BitBlt to the bitmap? ... don't match exactly to the background color, will this affect the 1 and 0 ... > closest color match of the foreground/background colors to the DIB color ... Maybe Blt-ing to the DIBSection is still ...
    (microsoft.public.pocketpc.developer)
  • Re: Signature control - 1 BPP bitmap
    ... the dib's color table to do the matching. ... > window to a DIB? ... >> as the foreground color on the destination surface, so if you blit a 1bpp ... then you'll see red and blue for the 1's/0's of the bitmap. ...
    (microsoft.public.pocketpc.developer)