bitmap doesn't display properly at higher resolutions/colors

bitmap doesn't display properly at higher resolutions/colors

Post by P& » Tue, 02 May 2000 04:00:00



I have an older program which was originally written for 256 colors
and 640x480 resolution.  It was hard coded and used DDBs.  I have
ported the ap to 32 bit and moved everything off to DIBs but the image
does not display properly.

The image data is captured real-time from a proprietary ISA board into
a buffer.  Setup structure contains things like the display window
handle, the width and height of the image to be captured.

In a nutshell, here is what I'm doing:

m_hdc =  GetDC(Setup.hDisplayWin);

m_aqMaxBmpLines= MAX_BITBUFSIZE / Setup.DspWidth;
m_nSizeBmpBits = (WORD) (Setup.DspWidth * (long)m_aqMaxBmpLines);

CreateCompatibleBitmap(m_hdc, Setup.DspWidth, m_aqMaxBmpLines);
SetBitmapDimensionEx(hBmp, Setup.DspWidth, m_aqMaxBmpLines, NULL);

// pBmpBits is set with the captured data from the card
i = SetBitmapBits(hBmp, Setup.DspWidth, pBmpBits);

// get a the palette so we can create the dib from it
hOldPal = GetStockObject(DEFAULT_PALETTE);
hPal = SelectPalette( m_hdc, hOldPal, FALSE );

// clear the old dib
if ( hDib )
{
        GlobalFree(hDib);
        hDib = NULL;

Quote:}

// create the new dib
hDib = DibFromBitmap ( hBmp, BI_RGB, 0, hPal ) ;

// return the palette to the HDC
SelectPalette( m_hdc, hPal, FALSE );

viTop = (int) AcqToVisiY(m_aqStartLine);
i = BitBlt(m_hdc, 0, viTop++, rVis.right, 1, m_hMemDC, 0, 0, SRCCOPY);

If my computer settings are for 256 colors and 640x480 then this code
will display the image properly.  Changing to 24bit and any higher
resolution causes the image to be display in a reduced size.

Can anyone tell me what the problem is?  If you need to see the whole
source module I have it.

Thanks,

Phil
p c   a t   n t a d m i n   d o t   c o m

 
 
 

bitmap doesn't display properly at higher resolutions/colors

Post by Chris Beck » Tue, 02 May 2000 04:00:00



> I have an older program which was originally written for 256 colors
> and 640x480 resolution.  It was hard coded and used DDBs.  I have
> ported the ap to 32 bit and moved everything off to DIBs but the image
> does not display properly.

The problem is, you havn't.

CreateComnpatibleBitmap creates a DDB at the primary displays bitdepth.

The SetBitmapBits you call is thus going to ... fail.

Your options are:

1. Keep the image data in a memory buffer that you allocate (ie a DIB), and
use StretchDIBits everytime you want to show the image.

2. Display the image data from a DDB (as you currently are). Instead of
using SetBitmapBits to keep the DDBsynchronous with your captured data use
SetDIBits().

3. Use CreateDIBSection - this creates a DIBSection object which is a GDI
bitmap with a pelbuffer accessible to usermode. You can maipulate memory
directly and immediately call BitBlt on the associated handle without having
to resort to SetDIBits.

Chris
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://www.mvps.org/user32

 
 
 

bitmap doesn't display properly at higher resolutions/colors

Post by P& » Tue, 02 May 2000 04:00:00


Quote:>CreateComnpatibleBitmap creates a DDB at the primary displays bitdepth.

>The SetBitmapBits you call is thus going to ... fail.

SetBitmapsBits() does not appear to be failing, appears more like it's
intrepeting the image data as pallette data.

Quote:>Your options are:

>1. Keep the image data in a memory buffer that you allocate (ie a DIB), and
>use StretchDIBits everytime you want to show the image.

>2. Display the image data from a DDB (as you currently are). Instead of
>using SetBitmapBits to keep the DDBsynchronous with your captured data use
>SetDIBits().

>3. Use CreateDIBSection - this creates a DIBSection object which is a GDI
>bitmap with a pelbuffer accessible to usermode. You can maipulate memory
>directly and immediately call BitBlt on the associated handle without having
>to resort to SetDIBits.

I think three is in order, now I need to find someone to write the
code as it is over my head.

Thanks
p c   a t   n t a d m i n   d o t   c o m

 
 
 

bitmap doesn't display properly at higher resolutions/colors

Post by Chris Beck » Tue, 02 May 2000 04:00:00



Quote:> >CreateComnpatibleBitmap creates a DDB at the primary displays bitdepth.

> >The SetBitmapBits you call is thus going to ... fail.
> SetBitmapsBits() does not appear to be failing, appears more like it's
> intrepeting the image data as pallette data.

Well yes. You are passing it 8bit data, and its interpreting it as ...
current bitdepth data (ie 16, 24, or 32 bits). It will tend to look wrong -
horizontally squashed with wierd colors is what you expect to get when image
data is interpreted with the wrong bit depth.

SetDIBits must be used when copying data to a DDB when the source format is
not equal to the current bit depth.

Chris
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://www.mvps.org/user32

 
 
 

bitmap doesn't display properly at higher resolutions/colors

Post by Petr Novotn » Wed, 03 May 2000 04:00:00



Quote:> >CreateComnpatibleBitmap creates a DDB at the primary displays bitdepth.

> >The SetBitmapBits you call is thus going to ... fail.
> SetBitmapsBits() does not appear to be failing, appears more like it's
> intrepeting the image data as pallette data.

If you don't call that a failure, I wonder what you really call a failure.
Blue Screen of Death perhaps?
 
 
 

1. 256 color resource bitmap does not display properly

Using VC++ and MFC:

I am trying to display a 256 color bitmap from a resource using
MFC.  Using a palette viewing utility, I can see that the palette
changes properly, but the bitmap still is displayed with mushed
colors.  If the Windows 95 system uses tan windows, the bitmap
has lots of tans.  If the Windows 95 sys has blue windows, the bitmap
has lots of blues, etc.  Bitmap is displayed with StretchBlt or BitBlt
using code from books.  I think I respond to WM_QUERYNEWPALETTE
and WM_PALETTECHANGED correctly.  This bitmap DOES
display perfectly in VC++ resource editor.

Any ideas?

--
Bob-o-Bob
Delphi and MFC Programming

Getting a Ph.D. didn't raise my opinion of myself,
it lowered my opinion of every other Ph.D.

2. Need Cable Drawing Package Recommendation

3. I can't properly display bitmap from *.BMP

4. Is PPP and LAN TCP/IP in Warp?

5. BitBlt on 256+ colors desktop doesn't display

6. Q258503

7. Can't display bitmap unless system palette is set to 256 colors

8. Setup program asks for original installation drive and directory !

9. drop down list box - doesn't drop, doesn't list, doesn't remember.

10. again, 256 color bitmap to non-256 color display

11. Bitblt displaying 256 colour bitmaps in 16 colours

12. display non-dithering colors for 256 color display