⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c.bak

📁 一个在brew中使用image显示的例子, 很适合新手学习
💻 BAK
📖 第 1 页 / 共 2 页
字号:

#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 + -