Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,

  my code snippet is blow:

void ScreenShot()
{
	
	AEEApplet* pMe = (AEEApplet*)GETAPPINSTANCE();
	IBitmap* pCurBitmap = IDISPLAY_GetDestination(pMe->m_pIDisplay);
	int nOrgW= 0, nOrgH = 0; 

	if(pCurBitmap)
	{
		IBITMAP_GetInfo(pCurBitmap, &bitmapInfo, sizeof(AEEBitmapInfo)); 				
		nOrgW = bitmapInfo.cx; 
		nOrgH = bitmapInfo.cy; 				
					
					
		JulianType jDate;
		char szFName[64];

		GETJULIANDATE(GETTIMESECONDS(), &jDate);		
		SPRINTF(	szFName, "logscr%d%.2d%.2d%.3d.bmp", 					
				jDate.wHour,
				jDate.wMinute,
				jDate.wSecond,
				GETTIMEMS() % 1000
				);						
		WriteBitmap(pCurBitmap, szFName, pMe->m_pIShell);
				
	      IBITMAP_Release(pCurBitmap);
	}


WB_RETURN WriteBitmap(IBitmap * dist, char * fname, IShell* pIShell)
{
    if(fname==NULL||dist==NULL) return ERR_PARAME;
	AEEBitmapInfo bitmapInfo; 
	IBITMAP_GetInfo(dist, &bitmapInfo, sizeof(AEEBitmapInfo)); 			

    int wid = bitmapInfo.cx;
    int hei = bitmapInfo.cy; 
    //int bcnt = sizeof(RGBVAL);
    int bcnt = 3; 
    int fwid = (wid * bcnt+3)/4;

    int bsize = fwid*4*hei;

    byte* bitbuf = (byte*)MALLOC(bsize);

    if(bitbuf==NULL) return ERR_RAMLOC;

    //MEMSET(bitbuf, 0x00U, bsize);
    for(int j=0; j>8;
            *(byte*)(bitbuf+j*fwid*4+i*bcnt) = (byte)(RGB_B(cv));
            *(byte*)(bitbuf+j*fwid*4+i*bcnt+1) = (byte)(RGB_G(cv));
            *(byte*)(bitbuf+j*fwid*4+i*bcnt+2) = (byte)(RGB_R(cv));
        }	


        BITMAPINFOHEADER bmpIH; int bmih = 40; //1sizeof(BITMAPINFOHEADER)
        BITMAPFILEHEADER  bmpFH; int bmfh= 14; //1sizeof(BITMAPFILEHEADER);

        MEMSET((void*)&bmpIH, 0, bmih);
        bmpIH.biSize = bmih;
        bmpIH.biWidth = 	wid;
        bmpIH.biHeight = 	hei;
        bmpIH.biPlanes = 	1;
        bmpIH.biBitCount	=  24;
        bmpIH.biCompression	= BI_RGB;
        bmpIH.biSizeImage	= bsize;

        bmpIH.biXPelsPerMeter =	0;
        bmpIH.biYPelsPerMeter	=	0;

        bmpIH.biClrUsed	= 0;
        bmpIH.biClrImportant	=0;

        MEMSET((void*)&bmpFH, 0, bmfh);
        bmpFH.bfType =0x4D42;	
        bmpFH.bfReserved1=0;
        bmpFH.bfReserved2=0;

        bmpFH.bfOffBits = 14+40;
        bmpFH.bfSize = bmpFH.bfOffBits+bsize;



        IFileMgr *pFileMgr;
        IFile *pFile;

        uint32 size = 0;

        //IShell* pIShell = (AEEApplet*)GETAPPINSTANCE()->m_pIShell;

        if((ISHELL_CreateInstance((IShell*)pIShell,
            AEECLSID_FILEMGR, (void **)&pFileMgr)) == SUCCESS)
        {
            OpenFileMode mode;
            if(IFILEMGR_Test(pFileMgr, fname) == SUCCESS)  mode = _OFM_READWRITE;
            else  mode = _OFM_CREATE;
            pFile = IFILEMGR_OpenFile(pFileMgr, (const char*)fname, mode) ;                                               
            if(pFile&&SUCCESS==IFILE_Seek(pFile, _SEEK_START, 0))
            {				
                size += IFILE_Write(pFile, &bmpFH, bmfh);
                size += IFILE_Write(pFile, &bmpIH, bmih);
                size += IFILE_Write(pFile, bitbuf, bsize);
                IFILE_Release(pFile);
            }
            IFILEMGR_Release(pFileMgr);
        }	
        FREE(bitbuf);
        if(size!=bmpFH.bfSize)return ERR_WRITEF;
        return SUC_RETURN;

 the statement "int nRetcode = IBITMAP_GetPixel(dist, i, jdx, &nc)" will return AEE_EBADPARM, the bitmap is 240*320,  i = 0, jdx=319,  the nRetcode = 14,  could you give me some advice?

 

does it work for all other values like i = 0, jdx=318. i mean the error 14 is returned only on boundries or while getting any pixel.

does it work for all other values like i = 0, jdx=318. i mean the error 14 is returned only on boundries or while getting any pixel.

I found that bitmap which is got by "IDISPLAY_GetDestination(pMe->m_pIDisplay)" is not able to get Pixel.
so I create a compatiable bitmap to get pixel.
 
IBitmap *pScreenshot = NULL;
IDIB* pIDIB = NULL;
do
{
AEEApplet* pMe = (AEEApplet*)GETAPPINSTANCE();
if (!pMe)
{
break;
}

IBitmap* pDeviceBmp = IDISPLAY_GetDestination( pMe->m_pIDisplay );
if (!pDeviceBmp)
{
break;
}

AEEBitmapInfo BitmapInfo = {0};
JInt nRetCode = IBITMAP_GetInfo(
pDeviceBmp,
&BitmapInfo,
sizeof(BitmapInfo) );
if ( nRetCode != SUCCESS || 0 == BitmapInfo.cx || 0 == BitmapInfo.cy )
{
IBITMAP_Release( pDeviceBmp );
break;
}

nRetCode = IBITMAP_CreateCompatibleBitmap(
pDeviceBmp,
&pScreenshot,
(int16)BitmapInfo.cx,
(int16)BitmapInfo.cy);
if ( nRetCode != SUCCESS || NULL == pScreenshot )
{
IBITMAP_Release( pDeviceBmp );
break;
}

nRetCode = IBITMAP_BltIn(
pScreenshot,
0,
0,
BitmapInfo.cx,
BitmapInfo.cy,
pDeviceBmp,
0,
0,
AEE_RO_COPY);
IBITMAP_Release( pDeviceBmp );
if ( nRetCode != SUCCESS)
{
break;
}

JulianType jDate = {0};
char szFName[64] = {0};

GETJULIANDATE(GETTIMESECONDS(), &jDate);
SPRINTF( szFName, "logscr%d%.2d%.2d%.3d.bmp",
jDate.wHour,
jDate.wMinute,
jDate.wSecond,
GETTIMEMS() % 1000
);

nRetCode = IBITMAP_QueryInterface(
pScreenshot,
AEECLSID_DIB,
(void**)&pIDIB);
if ( nRetCode != SUCCESS || NULL == pIDIB )
{
break;
}

WriteBitmap( pIDIB, szFName, pMe->m_pIShell );

} while ( JFalse );

if ( pIDIB != NULL )
{
IDIB_Release(pIDIB);
}

if ( pScreenshot != NULL )
{
IBITMAP_Release(pScreenshot);
}
 
It works well. thank you!
 

I found that bitmap which is got by "IDISPLAY_GetDestination(pMe->m_pIDisplay)" is not able to get Pixel.
so I create a compatiable bitmap to get pixel.
 
IBitmap *pScreenshot = NULL;
IDIB* pIDIB = NULL;
do
{
AEEApplet* pMe = (AEEApplet*)GETAPPINSTANCE();
if (!pMe)
{
break;
}

IBitmap* pDeviceBmp = IDISPLAY_GetDestination( pMe->m_pIDisplay );
if (!pDeviceBmp)
{
break;
}

AEEBitmapInfo BitmapInfo = {0};
JInt nRetCode = IBITMAP_GetInfo(
pDeviceBmp,
&BitmapInfo,
sizeof(BitmapInfo) );
if ( nRetCode != SUCCESS || 0 == BitmapInfo.cx || 0 == BitmapInfo.cy )
{
IBITMAP_Release( pDeviceBmp );
break;
}

nRetCode = IBITMAP_CreateCompatibleBitmap(
pDeviceBmp,
&pScreenshot,
(int16)BitmapInfo.cx,
(int16)BitmapInfo.cy);
if ( nRetCode != SUCCESS || NULL == pScreenshot )
{
IBITMAP_Release( pDeviceBmp );
break;
}

nRetCode = IBITMAP_BltIn(
pScreenshot,
0,
0,
BitmapInfo.cx,
BitmapInfo.cy,
pDeviceBmp,
0,
0,
AEE_RO_COPY);
IBITMAP_Release( pDeviceBmp );
if ( nRetCode != SUCCESS)
{
break;
}

JulianType jDate = {0};
char szFName[64] = {0};

GETJULIANDATE(GETTIMESECONDS(), &jDate);
SPRINTF( szFName, "logscr%d%.2d%.2d%.3d.bmp",
jDate.wHour,
jDate.wMinute,
jDate.wSecond,
GETTIMEMS() % 1000
);

nRetCode = IBITMAP_QueryInterface(
pScreenshot,
AEECLSID_DIB,
(void**)&pIDIB);
if ( nRetCode != SUCCESS || NULL == pIDIB )
{
break;
}

WriteBitmap( pIDIB, szFName, pMe->m_pIShell );

} while ( JFalse );

if ( pIDIB != NULL )
{
IDIB_Release(pIDIB);
}

if ( pScreenshot != NULL )
{
IBITMAP_Release(pScreenshot);
}
 
It works well. thank you!