how to create a screenshot? | developer.brewmp.com how to create a screenshot? | developer.brewmp.com

Developer

how to create a screenshot?

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?