how to use StretchDIBits to display grayscale images 
Author Message
 how to use StretchDIBits to display grayscale images
Make sure each scanline of the bitmap is DWORD aligned. Add extra padding if
not.

Feng Yuan  ( for the GDI book to read, check www.fengyuan.com )



Tue, 19 Aug 2003 12:56:43 GMT  
 how to use StretchDIBits to display grayscale images
What are you trying to do? Do you want to convert an 8-bit bitmap to
24-bits? Or are you just trying to display the image with your display set
to 24-bits?
If you just want to display the image, StretchDIBits will handle that.
If you want to convert it, you can still do this without duplicating the
image yourself.
BTW, the RGBTRIPLET used for 24-bit color has the format BGR. You don't
notice because the image is grayscale.


Quote:
> Dear Folks:
> I'm using StretchDIBits to display an RGB8 image (grayscale). I set the
> bmiHeader.biBitCount of my BITMAPINFO to 24 and make a duplication of the
> RGB fields as follows: R R R G G G B B B
> when I pass the buffer containing RRRGGGBBB to StretchDIBits, the
displayed
> image has a shift (see the attached example in bmp).
> Any idea how to make this work or how to use the StretchDIBits to display
> grayscale images?
> PS when using color images, StretchDIBits works fine!

> Thanks a lot.



Tue, 19 Aug 2003 14:16:14 GMT  
 how to use StretchDIBits to display grayscale images
Dear Feng,
I suspect what you say is very true. I don't know how to do this DWORD
alignement though. Any help?

Code details:
I have a certain m_pDisplay buffer (of type BYTE*). The buffer size is
3*m_iPictureWidth*iPictureHeight
and I call the display function this way:

StretchDIBits(hdc, 0, 0, iDestWidth, iDestHeight, 0, 0,
     m_iPictureWidth, m_iPictureHeight, m_pDisplay, &m_bmi, DIB_RGB_COLORS,
SRCCOPY);
the bitmap info is initialized as follows:

 memset(&m_bmi, 0, sizeof(BITMAPINFOHEADER));
 m_bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 m_bmi.bmiHeader.biWidth = m_iPictureWidth;
 m_bmi.bmiHeader.biHeight = -m_iPictureHeight;
 m_bmi.bmiHeader.biPlanes = 1;
 m_bmi.bmiHeader.biCompression = BI_RGB;
 m_bmi.bmiHeader.biBitCount = 24;


Quote:
> Make sure each scanline of the bitmap is DWORD aligned. Add extra padding
if
> not.

> Feng Yuan  ( for the GDI book to read, check www.fengyuan.com )



Tue, 19 Aug 2003 16:06:04 GMT  
 how to use StretchDIBits to display grayscale images

Quote:

> Dear Folks:
> I'm using StretchDIBits to display an RGB8 image (grayscale). I set the
> bmiHeader.biBitCount of my BITMAPINFO to 24 and make a duplication of the
> RGB fields as follows: R R R G G G B B B
> when I pass the buffer containing RRRGGGBBB to StretchDIBits, the
> displayed
> image has a shift (see the attached example in bmp).
> Any idea how to make this work or how to use the StretchDIBits to display
> grayscale images?
> PS when using color images, StretchDIBits works fine!

> Thanks a lot.

"Lena" is 258x258. It sure looks like you aren't obeying the rules for
padding scan line lengths to a multiple of 16. double check the
documentation, and when you copy from gray to color, be sure to do it a
scanline at a time, and watch those pad bytes.


Tue, 19 Aug 2003 16:12:57 GMT  
 how to use StretchDIBits to display grayscale images
Thanks a lot for the reply Phillip. Do you mean I should make zero padding
or just duplicate the latest value of the image on a certain row, or is
there another rule for padding?
Thanks a lot.
Quote:
> "Lena" is 258x258. It sure looks like you aren't obeying the rules for
> padding scan line lengths to a multiple of 16. double check the
> documentation, and when you copy from gray to color, be sure to do it a
> scanline at a time, and watch those pad bytes.



Tue, 19 Aug 2003 16:48:15 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how to use StretchDIBits to display grayscale images

2. aligning and displaying grayscale images

3. Display char-array as grayscale image??

4. how to draw grayscale image?

5. Blit Grayscale Image

6. BitBlt & Grayscale Images

7. How can I draw an image in grayscale?

8. Converting Image to Grayscale with .NET

9. 256 GrayScale bitmap, want to display the same as COLOR_3DFACE

10. StretchDIBits efficiency with flipped image

11. jpeg->DIB and then use stretchDIbits to display

12. quick n easy display : StretchDIBits , SetDIBits ...??

 

 
Powered by phpBB® Forum Software