views:

272

answers:

2

I have an array of raw rgb data. I would like to know how can I draw this pixels on the screen in Windows OS?

Now I use API function DrawDIBits, but I must turn up my image data.

A: 

If you mean drawing it without reversing the (R,G,B) into (B,G,R), I don't know an automatic way to do that.

If you mean drawing it without padding each line to a multiple of 4 pixels, you can do it by drawing each line one at a time. It will be slow, though.

Mark Ransom
+3  A: 

I always use SetDiBitsToDevice, but drawDIBits could be okay as well (haven't checked).

As for the upside-down nature of the windows blit functions:

There is a workaround. If you pass a BITMAPINFOHEADER or BITMAPINFO structure to the function just negate the value in the bitmap-height member. This will tell GDI to do the blit as if the height would be positive, but interpret the data as beeing stored in a top-down order.

You may get a nice speed improvement by this "hack" as well.

If you want to shuffle the byte-order of the pixels (e.g. turn ARGB into BGRA or so) you can use the BITMAPV4HEADER structure and tell GDI how your pixel-data is organized. That's a functionality that is rarely used but works since WIN98. I'd say it's save to use it these days..

Nils Pipenbrinck
I checked the docs for BITMAPV4HEADER, and I don't see a way to reverse RGB order, except by using BI_BITFIELDS - and that only works at 16/32BPP, not 24BPP.
Mark Ransom
Oh - that's true. I rarely use the 24 bit format, didn't knew that the BI_BITFIELDS don't work with 24bpp.
Nils Pipenbrinck