初级会员

- 积分
- 82
- 金钱
- 82
- 注册时间
- 2015-3-12
- 在线时间
- 9 小时
|

楼主 |
发表于 2015-12-8 20:22:12
|
显示全部楼层
void savepicture(void)
{
FRESULT res,res1,res2;
UINT WRBytes;
FIL fileW;
DIR picdir; //目录
u16 i,j;
u16 Line_buf[600];
static char char_i[1];
u32 Date,Time;
static char string20[25]; //根目录={"0:/"}
static char string21[15]; //日期目录={" "}
static char string22[3]; //={"/"}
static char string23[15]; //时间={" "}
static char string24[5]; //={".bmp"}
static char dir_path2[25]; //={" "}
static char file_path2[25]; //={" "}
memset(string20,0,25);
memset(string21,0,15);
memset(string22,0,3);
memset(string23,0,15);
memset(string24,0,5);
memset(dir_path2,0,25);
memset(file_path2,0,25);
strcpy(string20, "0:/");
strcpy(string21, " ");
strcpy(string22, "/");
strcpy(string23, " ");
strcpy(string24, ".bmp");
strcpy(dir_path2, " ");
strcpy(file_path2," ");
Date=calendar.w_year*10000+calendar.w_month*100+calendar.w_date; //获取日期
convert(string21,Date); //日期转换为字符串
Time=calendar.hour*10000+calendar.min*100+calendar.sec; //获取时间
convert(string23,Time); //时间转换为字符串
strcat(string20,string21); //合成文件夹路径
strcpy(dir_path2,string20);
strcat(string20,string22); //合成文件路径
strcat(string23,string24);
strcat(string20,string23);
strcpy(file_path2,string20);
res=f_mount(fs[0],"0:",1); //挂载SD卡
if(res)
{
Show_Str(0,450,192,24,"SD mount failed!",24,0);
delay_ms(1000);
LCD_Fill(0,450,192,474,BLACK);
}
res1 = f_opendir(&picdir,(TCHAR *)dir_path2);//打开目录
if(res1!=FR_OK)
{
res2 = f_mkdir((TCHAR *)dir_path2); //创建目录
}
if((res2==FR_EXIST)||(res1==FR_OK))
{ //如果目录存在,根据时间创建文件
res = f_open(&fileW,(TCHAR *)file_path2, FA_CREATE_ALWAYS|FA_WRITE); //文件不存在则创建新文件 //f_open (FIL* fp, const TCHAR* path, BYTE mode);
Show_Str(40,450,192,24,"saving......",24,0);
WriteHeader(&fileW);
WriteBMPInfo(&fileW);
for(i=440;i>40;i--)
{
memset(char_i,0,1);
convert(char_i,i);
Show_Str(140,450,192,24,(u8 *)char_i,24,0);
for(j=40;j<640;j++)
{
Line_buf[j-40]=LCD_ReadPoint(j,i);
}
f_write(&fileW,(u8*)Line_buf,1200,&WRBytes);
}
f_close (&fileW); //关闭文件
Show_Str(40,450,192,24,"Save .bmp finished!",24,0);
delay_ms(2000);
LCD_Fill(40,450,192,474,BLACK);
} |
|