📄 snapscreen.c
字号:
#include "AEEAppGen.h"
#include "AEEIMAGE.h"
#include "AEEFile.h"
#include "AEEStdLib.h"
#include "alpha.h"
#define BI_RGB 0L
#define BI_BITFIELDS 3L
#define RELEASEOBJ(p) ReleaseObj((IBase**)&p)
void ReleaseObj(IBase ** ppObj);
void ReleaseObj(IBase ** ppObj){
if ( ppObj && *ppObj ){
(void)IBASE_Release(*ppObj);
*ppObj = NULL;
}
}
#if defined(WIN32) || defined(AEE_SIMULATOR)
# pragma pack(push,2)
#define PACKED
#endif
typedef PACKED struct tagBITMAPFILEHEADER {
word bfType;
dword bfSize;
word bfReserved1;
word bfReserved2;
dword bfOffBits;
} BITMAPFILEHEADER, *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
typedef PACKED struct tagBITMAPINFOHEADER{
dword biSize;
long biWidth;
long biHeight;
word biPlanes;
word biBitCount;
dword biCompression;
dword biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
dword biClrUsed;
dword biClrImportant;
} BITMAPINFOHEADER, *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct tagRGBQUAD{
byte rgbBlue;
byte rgbGreen;
byte rgbRed;
byte rgbReserved;
}RGBQUAD;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO, *PBITMAPINFO;
#if defined(WIN32) || defined(AEE_SIMULATOR)
# pragma pack(pop)
#endif
boolean SaveScreen(void *pApp)
{
IBitmap *pBmp = NULL;
IBitmap *pCmpBmp = NULL;
IDIB *pDib = NULL;
IFileMgr*pFm = NULL;
IFile *pF = NULL;
int result;
BITMAPFILEHEADER bfh = {0};
BITMAPINFOHEADER bih = {0};
// RGBQUAD rgbQuad[256] = {0};
dword arMasks[3] = {0xF800,0x7E0,0x1F};
// uint32 bytesPerPixel;
// uint32 extraBytes;
uint32 adjustedLineSize;
uint32 sizeOfImageData;
AEEBitmapInfo bi = {0};
char szFileName[50]={0};
AEEApplet *pMe = (AEEApplet *)pApp;
result = IDISPLAY_GetDeviceBitmap(pMe->m_pIDisplay, &pBmp);
if (SUCCESS != result )
{
return FALSE;
}
result = IBITMAP_GetInfo(pBmp, &bi, sizeof(AEEBitmapInfo));
if (SUCCESS != result )
{
goto error;
}
result = IBITMAP_CreateCompatibleBitmap(pBmp, &pCmpBmp, (uint16)bi.cx, (uint16)bi.cy);
if (SUCCESS != result )
{
goto error;
}
result = IBITMAP_BltIn(pCmpBmp, 0,0, bi.cx, bi.cy, pBmp, 0, 0, AEE_RO_COPY);
if (SUCCESS != result )
{
goto error;
}
result = IBITMAP_QueryInterface(pCmpBmp, AEECLSID_DIB, (void**)&pDib);
if (SUCCESS != result )
{
goto error;
}
bih.biBitCount = pDib->nDepth;//每个像素位数大小
bih.biCompression = BI_BITFIELDS ;
bih.biHeight = (pDib->nPitch<0)?(pDib->cy):(0l-pDib->cy);//高度
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER); //sizeof(BITMAPINFOHEADER);
bih.biSizeImage = 0; //图像数据大小
bih.biWidth = pDib->cx; //宽度
bih.biXPelsPerMeter = 0; // Not used
bih.biYPelsPerMeter = 0; // Not used
bih.biClrUsed = 0; // Not used
bih.biClrImportant = 0; // Not used
// bytesPerPixel = ((uint32)bih.biBitCount)>>3;
// extraBytes = ((uint32)bih.biWidth * bytesPerPixel) % 4;
// adjustedLineSize = bytesPerPixel * ((uint32)bih.biWidth + extraBytes);
adjustedLineSize = ABS(pDib->nPitch);
sizeOfImageData = (uint32)(pDib->cy * adjustedLineSize);
bfh.bfType = (word)0x4d42;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)+ sizeof(arMasks);//到位图数据的偏移量
bfh.bfSize = bfh.bfOffBits + sizeOfImageData;
// bfh.bfSize = bfh.bfOffBits + pDib->cy * pDib->cx;//文件总的大小
SPRINTF(szFileName, "screen_%d.bmp", GETTIMEMS());
ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_FILEMGR, (void**)(&pFm));
if (NULL == pFm) {
goto error;
}
pF = IFILEMGR_OpenFile(pFm, szFileName, _OFM_CREATE);
if (NULL == pF) {
goto error;
}
result = IFILE_Write(pF, &bfh, sizeof(bfh));
if (result == 0) {
goto error;
}
result = IFILE_Write(pF, &bih, sizeof(bih));
if (result == 0) {
goto error;
}
result = IFILE_Write(pF, &arMasks, sizeof(arMasks));
if (result == 0) {
goto error;
}
result = IFILE_Write(pF, pDib->pBmp, sizeOfImageData);
if (result == 0) {
goto error;
}
RELEASEOBJ(pF);
RELEASEOBJ(pFm);
RELEASEOBJ(pDib);
RELEASEOBJ(pBmp);
RELEASEOBJ(pCmpBmp);
return TRUE;
error:
RELEASEOBJ(pF);
RELEASEOBJ(pFm);
RELEASEOBJ(pDib);
RELEASEOBJ(pBmp);
RELEASEOBJ(pCmpBmp);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -