怎么截屏啊?无论手机或者是在模拟器上 | developer.brewmp.com 怎么截屏啊?无论手机或者是在模拟器上 | developer.brewmp.com

Developer

怎么截屏啊?无论手机或者是在模拟器上

Forums:

我想截屏,无论用手机还是用模拟器,只要能够截屏下来就行,希望给点建议啊!!多谢了!!

开发一个应用,使用BREW短信在后台触发此应用,即在下面事件中进行保存屏幕的处理:
        case EVT_APP_MESSAGE:            ScreenCopy2File(pMe); // Draw text on display screen.           return TRUE;
下面是参考实现:
/*=========================================================================Macro definitions========================================================================== */#define RGB565TORGB555(rgb565) \     (rgb565 & 0x001f)      |  \ ((rgb565 & 0x07E0) >>1) |  \    ((rgb565 & 0xf800) >> 1)
#define  BMP_FLAG  "BM"
#ifdef AEE_SIMULATOR#pragma pack(push)#pragma pack(1)
#define __packed#endif
typedef  __packed struct   _BITMAPFILEHEADER   {     uint16 bfType;   //   位图文件的类型,必须为BM     uint32 bfSize;   //   位图文件的大小,以字节为单位       uint16 bfReserved1;   //   位图文件保留字,必须为0     uint16 bfReserved2;   //   位图文件保留字,必须为0     uint32 bfOffBits;   //   位图数据的起始位置,以相对于位图                           //   文件头的偏移量表示,以字节为单位   }BITMAPFILEHEADER;
typedef  __packed struct   _BITMAPINFOHEADER{     uint32   biSize;      //   本结构所占用字节数     uint32 biWidth;       //   位图的宽度,以像素为单位     uint32 biHeight;      //   位图的高度,以像素为单位     uint16   biPlanes;    //   目标设备的级别,必须为1     uint16   biBitCount;  //   每个像素所需的位数,必须是1(双色),                           //   4(16色),8(256色)或24(真彩色)之一     uint32   biCompression;   //   位图压缩类型,必须是   0(不压缩),                               //   1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一     uint32   biSizeImage;     //   位图的大小,以字节为单位     uint32 biXPelsPerMeter;   //   位图水平分辨率,每米像素数     uint32 biYPelsPerMeter;   //   位图垂直分辨率,每米像素数     uint32   biClrUsed;       //   位图实际使用的颜色表中的颜色数     uint32   biClrImportant;  //   位图显示过程中重要的颜色数   } BITMAPINFOHEADER;  
typedef __packed  struct   _RGBQUAD   {       uint8 rgbBlue;//   蓝色的亮度(值范围为0-255)       uint8 rgbGreen;   //   绿色的亮度(值范围为0-255)       uint8 rgbRed;   //   红色的亮度(值范围为0-255)       uint8 rgbReserved;//   保留,必须为0   } RGBQUAD;  
typedef  __packed struct   _BitmapHeader   {     BITMAPFILEHEADER bmFileHeader;  BITMAPINFOHEADER bmInfoHeader;   //   位图信息头     RGBQUAD   bmiColors[1];   //   颜色表   } BitmapHeader;  
#ifdef AEE_SIMULATOR#pragma pack(pop)#endif
static void SaveScreen(CScreenCopy *pMe, IBitmap **ppScreenBitmap){    IBitmap *pBitmapDisplay = NULL;    IDISPLAY_GetDeviceBitmap( pMe->a.m_pIDisplay, &pBitmapDisplay );    if(pBitmapDisplay)    {        IBITMAP_CreateCompatibleBitmap( pBitmapDisplay,             ppScreenBitmap,            pMe->DeviceInfo.cxScreen,             pMe->DeviceInfo.cyScreen);                if(*ppScreenBitmap)        {            IBitmap_BltIn(*ppScreenBitmap,                    0,                    0,                    pMe->DeviceInfo.cxScreen,                    pMe->DeviceInfo.cyScreen,                    pBitmapDisplay,                    0,                    0,                    AEE_RO_COPY);        }        IBITMAP_Release(pBitmapDisplay);    }}
int GetDIB(IBitmap *pib, IDIB **ppdib){   int nErr;   nErr = IBITMAP_QueryInterface(pib, AEECLSID_DIB, (void**)ppdib);#ifdef AEECLSID_DIB_20   // We're compiling with 2.1+, where AEECLSID_DIB is non-invalidating   // Try to invalidate if it succeeded, and try the old DIB if it failed   if (nErr != SUCCESS)    {      nErr = IBITMAP_QueryInterface(pib, AEECLSID_DIB_20, (void**)ppdib);   }#endif   return nErr;}
static int SaveToBmpFile(CScreenCopy *pMe, IBitmap *pBmp, const char *szFileName){ IDIB *pDib = NULL;    IFile *pIFile = NULL;
 //int index = 0; int BytesWriten = 0; int32 CountBytesWriten; BitmapHeader Header;    //int nRet;
    // check pointer if ( pBmp == NULL || szFileName == NULL ) {     return -1;    }
 if ( IFILEMGR_Test(pMe->m_pIFileMgr, szFileName) == SUCCESS)    {         IFILEMGR_Remove(pMe->m_pIFileMgr, szFileName);    }
    // open file to write    pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr,(const char *)szFileName, _OFM_CREATE);    if(pIFile == NULL)    {     return -2;    }
    // clear Header MEMSET((void *)&Header, 0, sizeof(Header));
    pDib = (IDIB *)pBmp;#if 0        nRet = GetDIB(pBmp, &pDib);    if(nRet != SUCCESS)    {        return -3;    }#endif        // "BM"    STRNCPY((char *)&Header.bmFileHeader.bfType, BMP_FLAG, 2*sizeof(char));    Header.bmFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)                                   + sizeof(BITMAPINFOHEADER)                         + pDib->cntRGB*sizeof(RGBQUAD); Header.bmFileHeader.bfSize = Header.bmFileHeader.bfOffBits + pDib->cy*pDib->nPitch;         Header.bmInfoHeader.biSize = sizeof(BITMAPINFOHEADER); Header.bmInfoHeader.biWidth = pDib->cx; Header.bmInfoHeader.biHeight = pDib->cy; Header.bmInfoHeader.biBitCount = pDib->nDepth; Header.bmInfoHeader.biXPelsPerMeter = 0; Header.bmInfoHeader.biYPelsPerMeter = 0; Header.bmInfoHeader.biClrUsed = pDib->cntRGB; Header.bmInfoHeader.biPlanes = 1; Header.bmInfoHeader.biSizeImage = pDib->cy*pDib->nPitch;
    // header except RGB colors arrays    CountBytesWriten = sizeof(Header) - sizeof(RGBQUAD);    BytesWriten = IFILE_Write(pIFile, (char *)&Header, CountBytesWriten);    if(BytesWriten != CountBytesWriten)    {        DBGPRINTF("IFILE_Write ret %d", BytesWriten);    }
    // RGB colors arrays if(pDib->cntRGB > 0) {        BytesWriten = IFILE_Write(pIFile, pDib->pRGB, pDib->cntRGB*sizeof(RGBQUAD));        if(BytesWriten != (int)(pDib->cntRGB*sizeof(RGBQUAD)))        {            DBGPRINTF("IFILE_Write ret %d", BytesWriten);        }    }   
    // 位图数据    {  uint8 *pSrc = pDib->pBmp + pDib->nPitch*(pDib->cy-1);  uint32 row = pDib->cy;  uint8 *tmp = NULL;  uint8 *pDest = NULL;  tmp = MALLOC(pDib->nPitch*pDib->cy);  if(tmp)  {     pDest = tmp;     while(row--)     {      MEMCPY(pDest, pSrc, pDib->nPitch);      if(16 == pDib->nDepth)      {       uint32 col = pDib->cx;       uint16 *p = (uint16 *)pDest;       while(col--)       {        *p = RGB565TORGB555(*p);        p++;       }      }      pDest += pDib->nPitch;      pSrc -= pDib->nPitch;     }     BytesWriten = IFILE_Write(pIFile, tmp,pDib->nPitch*pDib->cy);                    FREE(tmp);  }  else  {     while(row--)     {      BytesWriten = IFILE_Write(pIFile, pSrc,pDib->nPitch);      pSrc -= pDib->nPitch;     }  } }
    //RELEASEIF(pDib);    IFILE_Release(pIFile);
 return SUCCESS;}
 
 
static void ScreenCopy2File(CScreenCopy * pMe){    SaveScreen(pMe, &pMe->m_pScreenBitmap);
 if(pMe->m_pScreenBitmap) {  SaveToBmpFile(pMe, pMe->m_pScreenBitmap, BITMAP_FILE_NAME);        RELEASEIF(pMe->m_pScreenBitmap); }}
 

开发一个应用,使用BREW短信在后台触发此应用,即在下面事件中进行保存屏幕的处理:
        case EVT_APP_MESSAGE:            ScreenCopy2File(pMe); // Draw text on display screen.           return TRUE;
下面是参考实现:
/*=========================================================================Macro definitions========================================================================== */#define RGB565TORGB555(rgb565) \     (rgb565 & 0x001f)      |  \ ((rgb565 & 0x07E0) >>1) |  \    ((rgb565 & 0xf800) >> 1)
#define  BMP_FLAG  "BM"
#ifdef AEE_SIMULATOR#pragma pack(push)#pragma pack(1)
#define __packed#endif
typedef  __packed struct   _BITMAPFILEHEADER   {     uint16 bfType;   //   位图文件的类型,必须为BM     uint32 bfSize;   //   位图文件的大小,以字节为单位       uint16 bfReserved1;   //   位图文件保留字,必须为0     uint16 bfReserved2;   //   位图文件保留字,必须为0     uint32 bfOffBits;   //   位图数据的起始位置,以相对于位图                           //   文件头的偏移量表示,以字节为单位   }BITMAPFILEHEADER;
typedef  __packed struct   _BITMAPINFOHEADER{     uint32   biSize;      //   本结构所占用字节数     uint32 biWidth;       //   位图的宽度,以像素为单位     uint32 biHeight;      //   位图的高度,以像素为单位     uint16   biPlanes;    //   目标设备的级别,必须为1     uint16   biBitCount;  //   每个像素所需的位数,必须是1(双色),                           //   4(16色),8(256色)或24(真彩色)之一     uint32   biCompression;   //   位图压缩类型,必须是   0(不压缩),                               //   1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一     uint32   biSizeImage;     //   位图的大小,以字节为单位     uint32 biXPelsPerMeter;   //   位图水平分辨率,每米像素数     uint32 biYPelsPerMeter;   //   位图垂直分辨率,每米像素数     uint32   biClrUsed;       //   位图实际使用的颜色表中的颜色数     uint32   biClrImportant;  //   位图显示过程中重要的颜色数   } BITMAPINFOHEADER;  
typedef __packed  struct   _RGBQUAD   {       uint8 rgbBlue;//   蓝色的亮度(值范围为0-255)       uint8 rgbGreen;   //   绿色的亮度(值范围为0-255)       uint8 rgbRed;   //   红色的亮度(值范围为0-255)       uint8 rgbReserved;//   保留,必须为0   } RGBQUAD;  
typedef  __packed struct   _BitmapHeader   {     BITMAPFILEHEADER bmFileHeader;  BITMAPINFOHEADER bmInfoHeader;   //   位图信息头     RGBQUAD   bmiColors[1];   //   颜色表   } BitmapHeader;  
#ifdef AEE_SIMULATOR#pragma pack(pop)#endif
static void SaveScreen(CScreenCopy *pMe, IBitmap **ppScreenBitmap){    IBitmap *pBitmapDisplay = NULL;    IDISPLAY_GetDeviceBitmap( pMe->a.m_pIDisplay, &pBitmapDisplay );    if(pBitmapDisplay)    {        IBITMAP_CreateCompatibleBitmap( pBitmapDisplay,             ppScreenBitmap,            pMe->DeviceInfo.cxScreen,             pMe->DeviceInfo.cyScreen);                if(*ppScreenBitmap)        {            IBitmap_BltIn(*ppScreenBitmap,                    0,                    0,                    pMe->DeviceInfo.cxScreen,                    pMe->DeviceInfo.cyScreen,                    pBitmapDisplay,                    0,                    0,                    AEE_RO_COPY);        }        IBITMAP_Release(pBitmapDisplay);    }}
int GetDIB(IBitmap *pib, IDIB **ppdib){   int nErr;   nErr = IBITMAP_QueryInterface(pib, AEECLSID_DIB, (void**)ppdib);#ifdef AEECLSID_DIB_20   // We're compiling with 2.1+, where AEECLSID_DIB is non-invalidating   // Try to invalidate if it succeeded, and try the old DIB if it failed   if (nErr != SUCCESS)    {      nErr = IBITMAP_QueryInterface(pib, AEECLSID_DIB_20, (void**)ppdib);   }#endif   return nErr;}
static int SaveToBmpFile(CScreenCopy *pMe, IBitmap *pBmp, const char *szFileName){ IDIB *pDib = NULL;    IFile *pIFile = NULL;
 //int index = 0; int BytesWriten = 0; int32 CountBytesWriten; BitmapHeader Header;    //int nRet;
    // check pointer if ( pBmp == NULL || szFileName == NULL ) {     return -1;    }
 if ( IFILEMGR_Test(pMe->m_pIFileMgr, szFileName) == SUCCESS)    {         IFILEMGR_Remove(pMe->m_pIFileMgr, szFileName);    }
    // open file to write    pIFile = IFILEMGR_OpenFile(pMe->m_pIFileMgr,(const char *)szFileName, _OFM_CREATE);    if(pIFile == NULL)    {     return -2;    }
    // clear Header MEMSET((void *)&Header, 0, sizeof(Header));
    pDib = (IDIB *)pBmp;#if 0        nRet = GetDIB(pBmp, &pDib);    if(nRet != SUCCESS)    {        return -3;    }#endif        // "BM"    STRNCPY((char *)&Header.bmFileHeader.bfType, BMP_FLAG, 2*sizeof(char));    Header.bmFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)                                   + sizeof(BITMAPINFOHEADER)                         + pDib->cntRGB*sizeof(RGBQUAD); Header.bmFileHeader.bfSize = Header.bmFileHeader.bfOffBits + pDib->cy*pDib->nPitch;         Header.bmInfoHeader.biSize = sizeof(BITMAPINFOHEADER); Header.bmInfoHeader.biWidth = pDib->cx; Header.bmInfoHeader.biHeight = pDib->cy; Header.bmInfoHeader.biBitCount = pDib->nDepth; Header.bmInfoHeader.biXPelsPerMeter = 0; Header.bmInfoHeader.biYPelsPerMeter = 0; Header.bmInfoHeader.biClrUsed = pDib->cntRGB; Header.bmInfoHeader.biPlanes = 1; Header.bmInfoHeader.biSizeImage = pDib->cy*pDib->nPitch;
    // header except RGB colors arrays    CountBytesWriten = sizeof(Header) - sizeof(RGBQUAD);    BytesWriten = IFILE_Write(pIFile, (char *)&Header, CountBytesWriten);    if(BytesWriten != CountBytesWriten)    {        DBGPRINTF("IFILE_Write ret %d", BytesWriten);    }
    // RGB colors arrays if(pDib->cntRGB > 0) {        BytesWriten = IFILE_Write(pIFile, pDib->pRGB, pDib->cntRGB*sizeof(RGBQUAD));        if(BytesWriten != (int)(pDib->cntRGB*sizeof(RGBQUAD)))        {            DBGPRINTF("IFILE_Write ret %d", BytesWriten);        }    }   
    // 位图数据    {  uint8 *pSrc = pDib->pBmp + pDib->nPitch*(pDib->cy-1);  uint32 row = pDib->cy;  uint8 *tmp = NULL;  uint8 *pDest = NULL;  tmp = MALLOC(pDib->nPitch*pDib->cy);  if(tmp)  {     pDest = tmp;     while(row--)     {      MEMCPY(pDest, pSrc, pDib->nPitch);      if(16 == pDib->nDepth)      {       uint32 col = pDib->cx;       uint16 *p = (uint16 *)pDest;       while(col--)       {        *p = RGB565TORGB555(*p);        p++;       }      }      pDest += pDib->nPitch;      pSrc -= pDib->nPitch;     }     BytesWriten = IFILE_Write(pIFile, tmp,pDib->nPitch*pDib->cy);                    FREE(tmp);  }  else  {     while(row--)     {      BytesWriten = IFILE_Write(pIFile, pSrc,pDib->nPitch);      pSrc -= pDib->nPitch;     }  } }
    //RELEASEIF(pDib);    IFILE_Release(pIFile);
 return SUCCESS;}
 
 
static void ScreenCopy2File(CScreenCopy * pMe){    SaveScreen(pMe, &pMe->m_pScreenBitmap);
 if(pMe->m_pScreenBitmap) {  SaveToBmpFile(pMe, pMe->m_pScreenBitmap, BITMAP_FILE_NAME);        RELEASEIF(pMe->m_pScreenBitmap); }}