S3C2440 測試程序(六) LCD顯示實驗2_觸摸小圖片切換大圖片
實驗效果:
點擊屏幕中的6副小圖片,可將該小圖片切換成全屏圖片。
1、欲實現(xiàn)小圖片,需將原來圖片壓縮,此處壓縮成原來的1/8。代碼如下:
void Paint_Bmp_Small(int x0,int y0,int h,int l,int k,unsigned char bmp[])
{
//從[x0,y0]至[h/k,l/k]為止被顯示被壓縮了1/k的圖片
int x,y;
U32 c;
int p = 0;
h = h/k;
l = l/k;
for( y = 0 ; y < l ; y++ ) // l=240/k
{
for( x = 0 ; x < h ; x++ ) // h=320/k
{
c = bmp[p+1] | (bmp[p]<<8) ; // bmp[] 680個為1line,總的480line
if ( ( (x0+x) < SCR_XSIZE_TFT) && ( (y0+y) < SCR_YSIZE_TFT) )
LCD_BUFFER[y0+y][x0+x] = c ;
p = p + 2*k ; //每line的每2個像素都跳過K個值
}
p = p+640*(k-1); //640個為1line,就是說每2line中間都跳過K-1個line
}
}
2、在原有觸摸屏取坐標(biāo)值程序中添加截取此6張圖的點擊區(qū)域的代碼:
if((xdata-xdata_save > 5)||(xdata-xdata_save < -5)
||(ydata-ydata_save > 5)||(ydata-ydata_save < -5))
{
Uart_Printf("X_value = %d,Y_value = %d,X_data = %d,Y_data = %dn",xdata,ydata,xdata_save,ydata_save);
if(( xdata >= 135)&&( xdata <= 226))
{
// 6張圖的坐標(biāo)區(qū)域
if(( ydata >=91 )&&( ydata <= 205))
gPictureNum = 1;
else if(( ydata >=233 )&&( ydata <= 347))
gPictureNum = 2;
else if(( ydata >=375 )&&( ydata <= 489))
gPictureNum = 3;
else if(( ydata >=517 )&&( ydata <= 631))
gPictureNum = 4;
else if(( ydata >=659 )&&( ydata <= 773))
gPictureNum = 5;
else if(( ydata >=802 )&&( ydata <= 916))
gPictureNum = 6;
}
}
3、主程序顯示代碼:
while(1)
{
if(gPictureNum)
{
switch(gPictureNum)
{
case 1:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture1_320_240);
break;
case 2:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture2_320_240);
break;
case 3:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture3_320_240);
break;
case 4:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture4_320_240);
break;
case 5:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture5_320_240);
break;
case 6:
LCD_displayScreen(0,0,0);
Paint_Bmp(0,0,320,240,picture6_320_240);
break;
default:
LCD_displayScreen(0,0,0);
Uart_Printf("Clear Screen! n");
}
gPictureNum = 0;
}
Paint_Bmp_Small(20,200,320,240,8,picture6_320_240);
Paint_Bmp_Small(70,200,320,240,8,picture5_320_240);
Paint_Bmp_Small(120,200,320,240,8,picture4_320_240);
Paint_Bmp_Small(170,200,320,240,8,picture3_320_240);
Paint_Bmp_Small(220,200,320,240,8,picture2_320_240);
Paint_Bmp_Small(270,200,320,240,8,picture1_320_240);
}
}