Accessing pixel data of a bitmap
Posted on 2001-08-26
I have recently come across the need to create some custom controls. One of these controls is basically an M x N area that has a bitmap blitted into it. However for speed reasons I am performing all rendering to an area of memory somewhere else at a colour depth of 8bpp. In order for my user to see what I am rendering to this off screen memory area I need to somehow copy this data to either:
a) The window that is going to display it
b) To a bitmap that I can then blit to the window
I also need to use this same techique to render bitmaps that the user loads from disk.
The software that I am currently creating is a tile map editor with custom functionality. The currently available editors will not handle what I need this editor to do, so I am forced to write my own. :(
So in summary I need:
1) Create a CBitmap from a chunk of memory at a colour depth of 8bpp. I guess I could use CBitmap::CreateBitmapIndirect()
2) Since I dont want to have to keep re-creating and destroying the above bitmap every time I change the off screen bitmap I need to find a way of somehow getting direct access to the pixel data of the created bitmap. However creating a CBitmap from a BITMAP copies the data pixel data and does not use the memory area as assigned in the BITMAP structure.
Since this software is not commercial I am willng to accept pointers to good already pre-written classes or libs that allow creation of a bitmap and allow direct access to its pixel data and / or palette for 8bpp modes. I've looked at CDIB but it doesn't appear to support the functionality that I need. Has anyone any experience with WinG, would this provide this kind of functioanlity, remembering that this is going to operate on parts of controls within dialogs?