?? image.c.bak
字號:
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEImage.h"
//#include "AEE.h"
#include "image.bid"
#include "AEEDisp.h"
#include "image_res.h"
#include "AEEStdlib.h"
//定義采樣頻率,隔sample取一
//the explanation of the sampleX and sampleY
//sampleX and sampleY are integer number, 100 stand for 1:1 ; 50 stand for 1:0.5 ;300 stand for 1:3
typedef struct _IMAGE
{
AEEApplet a;
IBitmap* m_pBitmap; //原位圖指針
IBitmap* m_pBitmap_OBJ;//目標位圖指針
IBitmap* m_pBitmap_OBJ_OBJ;//第二個目標位圖
IBitmap* pbmScreen;//屏幕顯示指針
//int16 x;
//int16 y;
//AEEBitmapInfo pinfo;
NativeColor pColor; //象素點的顏色
uint16 i;//循環變量,要足夠大,即65536>原位圖文件的長和寬
uint16 j;
uint32 timer1;//用來記錄loadbitmap的時間
uint32 timer2;//用來記錄顯示源位圖的時間
// uint32 timer3;//用來記錄縮放并顯示的時間
AECHAR timer_char1[32];
AECHAR timer_char2[32];
// AECHAR timer_char3[32]={0};
AEEBitmapInfo bi;
// uint16 new_x;
// uint16 new_y;
} MyImage;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean image_HandleEvent(IApplet* pi, AEEEvent eCode, uint16 wParam,
uint32 dwParam);
static int Bitmap_LoadResources(MyImage* pMe);
static int Bitmap_sampling(MyImage* pMe, uint16 sampleX, uint16 sampleY);
int AEEClsCreateInstance(AEECLSID ClsId, IShell* pIShell, IModule* po,
void** ppObj)
{
*ppObj = NULL;
if (ClsId == AEECLSID_IMAGE)
{
if (AEEApplet_New(sizeof(MyImage), ClsId, pIShell, po,
(IApplet * *) ppObj, (AEEHANDLER) image_HandleEvent, NULL) ==
TRUE)
{
// Add your code here .....
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
static boolean image_HandleEvent(IApplet* pi, AEEEvent eCode, uint16 wParam,
uint32 dwParam)
{
MyImage* pMe = (MyImage*) pi;
int i;
// uint32 time;
// AECHAR fmt[]={'%','d',0};
// AECHAR score_name[32]={0};
switch (eCode)
{
case EVT_APP_START:// pMe->timer_char1[32]=0;
// pMe->timer_char2[32]={0};
for (i = 0; i < 32; i++)
{
pMe->timer_char1[i] = 0;
pMe->timer_char2[i] = 0;
}
IDISPLAY_Update(pMe->a.m_pIDisplay);
return(TRUE);
case EVT_APP_STOP://Free the memory
if (pMe->m_pBitmap)
{
IBITMAP_Release(pMe->m_pBitmap);
pMe->m_pBitmap = NULL;
}
if (pMe->m_pBitmap_OBJ)
{
IBITMAP_Release(pMe->m_pBitmap_OBJ);
pMe->m_pBitmap_OBJ = NULL;
}
if (pMe->m_pBitmap_OBJ_OBJ)
{
IBITMAP_Release(pMe->m_pBitmap_OBJ_OBJ);
pMe->m_pBitmap_OBJ_OBJ = NULL;
}
if (pMe->pbmScreen)
{
IBITMAP_Release(pMe->pbmScreen);
pMe->pbmScreen = NULL;
}
return TRUE;
case EVT_KEY:switch (wParam)
{
case AVK_1 ://取樣函數
//sampling(pMe,pMe->m_pBitmap,pMe->m_pBitmap_OBJ,sampleX,sampleY);
//////////////////////////////////////////////////////////////////////////
Bitmap_LoadResources(pMe);
// Bitmap_sampling(pMe,50,50);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
//按下2,以另外的一個比例縮放
case AVK_2 :Bitmap_sampling(pMe, 50, 50);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
case AVK_3://time=ISHELL_GetTimeMS(pMe->a.m_pIShell);
//WSPRINTF(score_name,32,fmt,time);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL,
pMe->timer_char1, -1, 20, 20, NULL, NULL);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL,
pMe->timer_char2, -1, 20, 50, NULL, NULL);
IDISPLAY_Update(pMe->a.m_pIDisplay);
default:break;
}
break;
default:break;
}
return FALSE;
}
/*===========================================================================
FUNCTION Bitmap_LoadResources
===========================================================================*/
#define CHECK_ERROR(e) nErr = (e); \
if (SUCCESS != nErr) { \
goto Error; \
}
#define CHECK_NULL(e) if (NULL == (e)) { \
nErr = EFAILED; \
goto Error; \
}
//////////////////////////////////////////////////////////////////////////
//FUNCTION BITMAP_LOADRESOURCES
//////////////////////////////////////////////////////////////////////////
static int Bitmap_LoadResources(MyImage* pMe)//, uint16 sampleX, uint16 sampleY)
{
IBitmap* pbmDib = NULL;
IBitmap* pbmDdb = NULL;
// AEEBitmapInfo bi;
int nErr;
//顯示時間
uint32 time1;
uint32 time2;
AECHAR fmt[] = { '%', 'd', 0 };
// AECHAR score_name[32]={0};
time1 = ISHELL_GetTimeMS(pMe->a.m_pIShell);
// CHECK_ERROR(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_IMAGE, (void**)&pMe->pISprite));
CHECK_NULL(pMe->pbmScreen = IDISPLAY_GetDestination(pMe->a.m_pIDisplay));
// load the res by the name of the file
// CHECK_NULL(pbmDib = ISHELL_LoadBitmap(pMe->a.m_pIShell, "lina.bmp")); //.bmpstage
// load the res by the ID of the Resource
CHECK_NULL(pbmDib = ISHELL_LoadResBitmap(pMe->a.m_pIShell, IMAGE_RES_FILE,
IM_LINA));
CHECK_ERROR(IBITMAP_GetInfo(pbmDib, &pMe->bi, sizeof(pMe->bi)));
CHECK_ERROR(IBITMAP_CreateCompatibleBitmap(pMe->pbmScreen,
&pMe->m_pBitmap, (uint16) pMe->bi.cx, (uint16) pMe->bi.cy));
CHECK_ERROR(IBITMAP_BltIn(pMe->m_pBitmap, 0, 0, (uint16) pMe->bi.cx,
(uint16) pMe->bi.cy, pbmDib, 0, 0, AEE_RO_COPY));
//to display the original bitmap::pMe->m_pBitmap
IDISPLAY_BitBlt(pMe->a.m_pIDisplay, 0, 0, (uint16) (pMe->bi.cx),
(uint16) (pMe->bi.cy), pMe->m_pBitmap, 0, 0, AEE_RO_COPY);
//計算timer1的值,并保存在數組中
time2 = ISHELL_GetTimeMS(pMe->a.m_pIShell);
pMe->timer1 = time2 - time1;
WSPRINTF(pMe->timer_char1, 32, fmt, pMe->timer1);//pMe->timer1);
//////////////////////////////////////////////////////////////////////////
IBITMAP_Release(pbmDib);
pbmDib = NULL;
Error:
if (pbmDib)
{
IBITMAP_Release(pbmDib);
}
if (pbmDdb)
{
IBITMAP_Release(pbmDdb);
}
return nErr;
}
//////////////////////////////////////////////////////////////////////////
//FUNCTION SAMPLING
//////////////////////////////////////////////////////////////////////////
static int Bitmap_sampling(MyImage* pMe, uint16 sampleX, uint16 sampleY)
{
uint16 new_x;
uint16 new_y;
int nErr;
uint32 time1;
uint32 time2;
AECHAR fmt[] = { '%', 'd', 0 };
new_x = 0;
new_y = 0;
//記錄起始時間
time1 = ISHELL_GetTimeMS(pMe->a.m_pIShell);
//創建目標位圖的兼容位圖pMe->m_pBitmap_OBJ,對X軸按照要求變換,而Y坐標不變
CHECK_ERROR(IBITMAP_CreateCompatibleBitmap(pMe->pbmScreen,
&pMe->m_pBitmap_OBJ,
(uint16) ((uint16) (pMe->bi.cx) * sampleX / 100),
(uint16) ((uint16) pMe->bi.cy)));
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//對X軸按照要求變換
for (pMe->j = 0; pMe->j <= (uint16) pMe->bi.cy; pMe->j++)//Y軸不變
switch (sampleX)
{
case 10://采樣率為1/10,每10個點采樣一個點
case 20://采樣率為20/100,每5個點采樣一個點
case 30://采樣率為30/100,每3個點采樣一個點
case 40://采樣率為40/100,每2個點采樣一個點
case 50://采樣率為50/100,每2個點采樣一個點
for (pMe->i = 0;
pMe->i <= (uint16) pMe->bi.cx;
pMe->i = pMe->i + 100 / sampleX)
{
//100/sampleX
//得到象素點
{
IBITMAP_GetPixel(pMe->m_pBitmap, pMe->i, pMe->j,
&pMe->pColor);
//寫到新的位圖中
IBITMAP_DrawPixel(pMe->m_pBitmap_OBJ, new_x++, new_y,
pMe->pColor, AEE_RO_COPY);
}
}
new_y++;
new_x = 0;
break;
case 60://固定取點;10個點,取6個,分別是0,2,3,5,6,8,
for (pMe->i = 0; pMe->i <= (uint16) pMe->bi.cx; pMe->i++)
{
switch (pMe->i % 10)
{
case 0:case 2:case 3:case 5:case 6:case 8://得到象素點
{
IBITMAP_GetPixel(pMe->m_pBitmap, pMe->i, pMe->j,
&pMe->pColor);
//寫到新的位圖中
IBITMAP_DrawPixel(pMe->m_pBitmap_OBJ, new_x++, new_y,
pMe->pColor, AEE_RO_COPY);
}
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -