实验效果:
点击屏幕中的6副小图片,可将该小图片切换成全屏图片。
1、欲实现小图片,需将原来图片压缩,此处压缩成原来的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、在原有触摸屏取坐标值程序中添加截取此6张图的点击区域的代码:
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 = %d\n",xdata,ydata,xdata_save,ydata_save);
if(( xdata >= 135)&&( xdata <= 226))
{
// 6张图的坐标区域
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);
}
}
上一篇:S3C2440 测试程序(七) IIC实验1--读写EEPROM(不开中断)
下一篇:S3C2440 测试程序(六) LCD显示实验1
推荐阅读最新更新时间:2024-03-16 15:23