How do I save a image from IBitmap? | developer.brewmp.com How do I save a image from IBitmap? | developer.brewmp.com

Developer

How do I save a image from IBitmap?

Forums:

now I have a bitmap instance.How can I save it in jpeg or png?

i am also struggling with te same problem.....u got any solution

i am also struggling with te same problem.....u got any solution

I think you can't save JPG or PNG from Ibitmap by using any avaliable APIs. Bad news is you have to write your own encoder for that.

I think you can't save JPG or PNG from Ibitmap by using any avaliable APIs. Bad news is you have to write your own encoder for that.

I am posting sample code for an example which captures the screen and save it into an image file. Though the format is of .bmp, we can save it into .jpg file and view the same in our PC.
Check out the following link to know Windows BMP format
http://local.wasp.uwa.edu.au/~pbourke/dataformats/bmp/
Here is the sequence of operations to be performed:
IBitmap * pIBitmap = NULL;
IDISPLAY_GetDeviceBitmap(pMe->m_pIDisplay, &pIBitmap); // here i assume that ptr for IDisplay interface is created
IDIB * pIDib = NULL;
IBITMAP_QueryInterface(pIBitmap, AEECLSID_DIB, (void**)&pIDib);
////////////////////////////////////////////////////////////////////
////// Now pIDib->pBmp holds teh pixel Data/////////////
/////////////////////////////////////////////////////////////////////
/* Create a .jpg file and write the above data into it in windowa bmp format */
/* normally we save as "image.bmp" file , But as you need to save it into a .jpg file, i am using "image.jpg" */
IFile * pBmpFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, "image.jpg", _OFM_CREATE);
HEADER header; /* HEADER --struct typedefined in the above link */
MEMSET((void *)&header, 0, sizeof(header));
INFOHEADER infoHeader; /* INFOHEADER --struct typedefined in the above link */
MEMSET((void *)&infoHeader, 0, sizeof(infoHeader));
// Create the file Header
/////////////////////////////
--------
header.type=
---------
--------
header.reserved1 = 0x0;
header.reserved2 = 0x0;
// Write the header to the file
//////////////////////////////////
IFILE_Write(pBmpFile, &header, sizeof(header));
// Create the file Info Header
/////////////////////////////
---------
--------
infoHeader.width = pIDib->cx;
infoHeader.height = pIDib->cy;
infoHeader.planes = 1;
---------
--------
// Write the Info header to the file
//////////////////////////////////
IFILE_Write(pBmpFile, &infoHeader, sizeof(infoHeader));
// Write the Color Table into the *.bmp file
//////////////////////////////////////////////////////////
if(pIDib->cntRGB > 0)
{
IFILE_Write(pBmpFile, pIDib->pRGB, pIDib->cntRGB);

// Create the Bitmap Table from pIDib->pIDib
/////////////////////////////
sizeOfTable = bmpPaddedRowLengthInBytes*imageHeightInPixels;
byte * pPixelsTable = (byte *) MALLOC(sizeOfTable);
// write the bit map table to the file
IFILE_Write(pBmpFile, pPixelsTable, sizeOfTable);
/////everything finished --release the resources if any
FREE(pPixelsTable);
IFILE_Release(pBmpFile);

I am posting sample code for an example which captures the screen and save it into an image file. Though the format is of .bmp, we can save it into .jpg file and view the same in our PC.
Check out the following link to know Windows BMP format
http://local.wasp.uwa.edu.au/~pbourke/dataformats/bmp/
Here is the sequence of operations to be performed:
IBitmap * pIBitmap = NULL;
IDISPLAY_GetDeviceBitmap(pMe->m_pIDisplay, &pIBitmap); // here i assume that ptr for IDisplay interface is created
IDIB * pIDib = NULL;
IBITMAP_QueryInterface(pIBitmap, AEECLSID_DIB, (void**)&pIDib);
////////////////////////////////////////////////////////////////////
////// Now pIDib->pBmp holds teh pixel Data/////////////
/////////////////////////////////////////////////////////////////////
/* Create a .jpg file and write the above data into it in windowa bmp format */
/* normally we save as "image.bmp" file , But as you need to save it into a .jpg file, i am using "image.jpg" */
IFile * pBmpFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr, "image.jpg", _OFM_CREATE);
HEADER header; /* HEADER --struct typedefined in the above link */
MEMSET((void *)&header, 0, sizeof(header));
INFOHEADER infoHeader; /* INFOHEADER --struct typedefined in the above link */
MEMSET((void *)&infoHeader, 0, sizeof(infoHeader));
// Create the file Header
/////////////////////////////
--------
header.type=
---------
--------
header.reserved1 = 0x0;
header.reserved2 = 0x0;
// Write the header to the file
//////////////////////////////////
IFILE_Write(pBmpFile, &header, sizeof(header));
// Create the file Info Header
/////////////////////////////
---------
--------
infoHeader.width = pIDib->cx;
infoHeader.height = pIDib->cy;
infoHeader.planes = 1;
---------
--------
// Write the Info header to the file
//////////////////////////////////
IFILE_Write(pBmpFile, &infoHeader, sizeof(infoHeader));
// Write the Color Table into the *.bmp file
//////////////////////////////////////////////////////////
if(pIDib->cntRGB > 0)
{
IFILE_Write(pBmpFile, pIDib->pRGB, pIDib->cntRGB);

// Create the Bitmap Table from pIDib->pIDib
/////////////////////////////
sizeOfTable = bmpPaddedRowLengthInBytes*imageHeightInPixels;
byte * pPixelsTable = (byte *) MALLOC(sizeOfTable);
// write the bit map table to the file
IFILE_Write(pBmpFile, pPixelsTable, sizeOfTable);
/////everything finished --release the resources if any
FREE(pPixelsTable);
IFILE_Release(pBmpFile);

Hi sreenivas,
It is different situation here.
In your case you can specify which image type to capture but here we have a Bitmap structure that you have to encode it to JPEG(Not capturing the JPEG).
Quote:IDISPLAY_GetDeviceBitmap(pMe->m_pIDisplay, &pIBitmap);
Also this function always gives you the raw bitmap.

Hi sreenivas,
It is different situation here.
In your case you can specify which image type to capture but here we have a Bitmap structure that you have to encode it to JPEG(Not capturing the JPEG).
Quote:IDISPLAY_GetDeviceBitmap(pMe->m_pIDisplay, &pIBitmap);
Also this function always gives you the raw bitmap.

hi
can anybody suggest a good png encoder

hi
can anybody suggest a good png encoder

refer to libpng.org

refer to libpng.org

quace wrote:now I have a bitmap instance.How can I save it in jpeg or png?
i am also struggling with the same problem.....If some body got the solution then please do reply ..
Rgards
abbay

quace wrote:now I have a bitmap instance.How can I save it in jpeg or png?
i am also struggling with the same problem.....If some body got the solution then please do reply ..
Rgards
abbay