save screen as a bitmap? | developer.brewmp.com save screen as a bitmap? | developer.brewmp.com

Developer

save screen as a bitmap?

Forums:

Hi, is there anyone know how to save the device screen as a bitmap file?
i have created a *bitmap and set it as the destination using IDISPLAY_SetDestination. And also i can show it on screen using IBITMAP_BltIn(). But i have no idea how to save this bitmap as a file ....

You can query the IBitmap for an IDIB pointer, which will let you access the raw bitmap data. Then you just need to construct the Windows BMP file header and write the data out to a file. You should be able to find plenty of documentation on this available on the internet.

You can query the IBitmap for an IDIB pointer, which will let you access the raw bitmap data. Then you just need to construct the Windows BMP file header and write the data out to a file. You should be able to find plenty of documentation on this available on the internet.

Can anyone post an example for doing that?
thanks.

Can anyone post an example for doing that?
thanks.

As Nathan suggested, get the BMP header documentation (MSDN is a good place to start). Allocate sufficient memory for bitmap header structure + your bitmap data. Put the bitmap header first in to the allocated memory and initialize it with valid information about your bitmap, now at the end of the header copy bitmap data.

As Nathan suggested, get the BMP header documentation (MSDN is a good place to start). Allocate sufficient memory for bitmap header structure + your bitmap data. Put the bitmap header first in to the allocated memory and initialize it with valid information about your bitmap, now at the end of the header copy bitmap data.

Morpheus,
This is really so simple that anyone with the slightest C/C++ abilty can do it, and it is explained in the SDK documentation as well, so what would you need the code for. Can't you do at least a minimum of thinking and work yourself? This is not a forum to spoon-feed the lazy!

Morpheus,
This is really so simple that anyone with the slightest C/C++ abilty can do it, and it is explained in the SDK documentation as well, so what would you need the code for. Can't you do at least a minimum of thinking and work yourself? This is not a forum to spoon-feed the lazy!

I'll throw in my lot with the lazy moron camp and say that it would be really nice to see an example.

I'll throw in my lot with the lazy moron camp and say that it would be really nice to see an example.

I need an ignore list in this forum. Max, any chance this board supports that so I am not even seeing posts coming from certain people? I am just sick and tired of wanna-be programmers who are too lazy to even learn the art and think they just need to constantly ask other people to do the work for them.
If you can't grasp a concept as simple as bitmap headers that have been documented to death and pointer references to parts of bitmap headers, you really should go and program in Logo or so, friends. Or maybe you should just start *learning* and *reading* for a change and drop the silver-spoon...

I need an ignore list in this forum. Max, any chance this board supports that so I am not even seeing posts coming from certain people? I am just sick and tired of wanna-be programmers who are too lazy to even learn the art and think they just need to constantly ask other people to do the work for them.
If you can't grasp a concept as simple as bitmap headers that have been documented to death and pointer references to parts of bitmap headers, you really should go and program in Logo or so, friends. Or maybe you should just start *learning* and *reading* for a change and drop the silver-spoon...

I had to spend a couple hours reading up and debugging to get this to work, and I don't think anyone else should have to go through the trouble of re-inventing the wheel, despite the fact that it is so easy according to some. It is adapted from here, so thanks to the author:
http://www.javaworld.com/javaworld/javatips/jw-javatip60-p2.html
I didn't end up using it, and only briefly tested it, but here is my code if anyone wants to give it a try (only tested on 8 bit images)...
void GraphicsUtil::WriteBitmap(IShell *shell, int width, int height, byte *imageData, char *path) {
int size = 40+14; // header
int pad = (4 - ((width * 3) % 4)) * height;
size += width*height*3 + pad;
byte *bitmapData = (byte *)MALLOC(size);
int biSizeImage = ((width * height) * 3) + pad;
// bitmap header
bitmapData[0] = 'B';
bitmapData[1] = 'M';
writeDWord(bitmapData, 2, size);
bitmapData[6] = 0; // reserved
bitmapData[7] = 0;
bitmapData[8] = 0;
bitmapData[9] = 0;
writeDWord(bitmapData, 10, 40+14);
// bitmap info header
writeDWord(bitmapData, 14, 40); // info header size
writeDWord(bitmapData, 18, width);
writeDWord(bitmapData, 22, height);
writeWord(bitmapData, 26, 1); // planes
writeWord(bitmapData, 28, 24); // bits
writeDWord(bitmapData, 30, 0); // compression
writeDWord(bitmapData, 34, biSizeImage);
writeDWord(bitmapData, 38, 0); // x pels/meter
writeDWord(bitmapData, 42, 0); // y pels/meter
writeDWord(bitmapData, 46, 0); // clrused
writeDWord(bitmapData, 50, 0); // clrimportant
// bitmap data
MEMCPY(bitmapData+54, imageData, width*height*3);
IFileMgr *fileMgr;
ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void **)&fileMgr);
if (IFILEMGR_Test(fileMgr, path)) {
IFILEMGR_Remove(fileMgr, path);
}
IFile *file = IFILEMGR_OpenFile(fileMgr, path, _OFM_CREATE);
IFILE_Write(file, bitmapData, size);
IFILE_Release(file);
IFILEMGR_Release(fileMgr)
FREEIF(bitmapData);

void GraphicsUtil::writeWord(byte *array, int offset, word value) {
array[offset] = (value & 0x00FF);
array[offset+1] = ((value >> 8) & 0x00FF);

void GraphicsUtil::writeDWord(byte *array, int offset, dword value) {
array[offset] = (value & 0x00FF);
array[offset+1] = ((value >> 8) & 0x000000FF);
array[offset+2] = ((value >> 16) & 0x000000FF);
array[offset+3] = ((value >> 24) & 0x000000FF);

I had to spend a couple hours reading up and debugging to get this to work, and I don't think anyone else should have to go through the trouble of re-inventing the wheel, despite the fact that it is so easy according to some. It is adapted from here, so thanks to the author:
http://www.javaworld.com/javaworld/javatips/jw-javatip60-p2.html
I didn't end up using it, and only briefly tested it, but here is my code if anyone wants to give it a try (only tested on 8 bit images)...
void GraphicsUtil::WriteBitmap(IShell *shell, int width, int height, byte *imageData, char *path) {
int size = 40+14; // header
int pad = (4 - ((width * 3) % 4)) * height;
size += width*height*3 + pad;
byte *bitmapData = (byte *)MALLOC(size);
int biSizeImage = ((width * height) * 3) + pad;
// bitmap header
bitmapData[0] = 'B';
bitmapData[1] = 'M';
writeDWord(bitmapData, 2, size);
bitmapData[6] = 0; // reserved
bitmapData[7] = 0;
bitmapData[8] = 0;
bitmapData[9] = 0;
writeDWord(bitmapData, 10, 40+14);
// bitmap info header
writeDWord(bitmapData, 14, 40); // info header size
writeDWord(bitmapData, 18, width);
writeDWord(bitmapData, 22, height);
writeWord(bitmapData, 26, 1); // planes
writeWord(bitmapData, 28, 24); // bits
writeDWord(bitmapData, 30, 0); // compression
writeDWord(bitmapData, 34, biSizeImage);
writeDWord(bitmapData, 38, 0); // x pels/meter
writeDWord(bitmapData, 42, 0); // y pels/meter
writeDWord(bitmapData, 46, 0); // clrused
writeDWord(bitmapData, 50, 0); // clrimportant
// bitmap data
MEMCPY(bitmapData+54, imageData, width*height*3);
IFileMgr *fileMgr;
ISHELL_CreateInstance(shell, AEECLSID_FILEMGR, (void **)&fileMgr);
if (IFILEMGR_Test(fileMgr, path)) {
IFILEMGR_Remove(fileMgr, path);
}
IFile *file = IFILEMGR_OpenFile(fileMgr, path, _OFM_CREATE);
IFILE_Write(file, bitmapData, size);
IFILE_Release(file);
IFILEMGR_Release(fileMgr)
FREEIF(bitmapData);

void GraphicsUtil::writeWord(byte *array, int offset, word value) {
array[offset] = (value & 0x00FF);
array[offset+1] = ((value >> 8) & 0x00FF);

void GraphicsUtil::writeDWord(byte *array, int offset, dword value) {
array[offset] = (value & 0x00FF);
array[offset+1] = ((value >> 8) & 0x000000FF);
array[offset+2] = ((value >> 16) & 0x000000FF);
array[offset+3] = ((value >> 24) & 0x000000FF);