hhakex 发表于 2013-8-18 20:50:49

stm32f103sd卡存储图片问题

我在使用SD卡存储摄像头采集回来的图片,总是无法打开,不知道是什么原因?求解释啊,这是bmp的源代码。
#include "bmp.h"
unsigned int buf;

/***************************************************************************/
FATFS fs;            // Work area (file system object) for logical drive
FIL fsrc, fdst;         // file objects
int aa = 0;
FRESULT res;            // FatFs function common result code
UINT br, bw;            // File R/W count
unsigned int i,j;
char name3=".bmp";   /*图像后缀名*/
RGBQUAD rgbquad;

BITMAPCOREHEADER bmphead; /* 存放SD卡的信息 */
BITMAPINFOHEADER bmpheadinfo;/* 存放SD卡的信息 */
/***************************************************************************/

/****************************************************************************
* 名    称:BMP_ENCODE()
* 功    能:将液晶屏像素值重新编码并保存至SD Card。
* 入口参数:filename                文件名
* 出口参数:
* 说    明:
****************************************************************************/

void BMP_ENCODE(char *filename)
{        int iii;
    strcat(filename,name3);//为filename添加".bmp"后缀
    f_mount(0, &fs);
    res = f_open(&fsrc,filename, FA_CREATE_ALWAYS | FA_WRITE); //创建一个BMP图片文件
    for( iii=0;iii<256;iii++)//写调色板灰度像素值
    {
      rgbquad.rgbBlue=iii;
      rgbquad.rgbGreen=iii;
      rgbquad.rgbRed=iii;
      rgbquad.rgbReserved=0;
    }
/***************给位图的文件头赋值********************/
    bmphead.bfType = 0x4d42;      
    bmphead.bfSize = 9600+54+1024;//图像总数据大小    bmphead.bfReserved1 = 0;
    bmphead.bfReserved2 = 0;
    bmphead.bfOffBits   = 54;//文件头信息总偏移量
/*************************end*************************/
   
/***************给位图的文件头信息赋值****************/
    bmpheadinfo.biSize =40;//40信息偏移量
    bmpheadinfo.biWidth =120;   //设置图像的纵向分辨率   
bmpheadinfo.biHeight =80;    //设置图像的横向分辨率
    bmpheadinfo.biPlanes =1;
    bmpheadinfo.biBitCount =8;   //像素深度8位
    bmpheadinfo.biCompression = 0;
    bmpheadinfo.biSizeImage =9600;//实际用到的像素数据大小
bmpheadinfo.biXPelsPerMeter =0;
    bmpheadinfo.biYPelsPerMeter = 0;
    bmpheadinfo.biClrUsed =0;
    bmpheadinfo.biClrImportant =0;
      
    res |= f_write(&fsrc, &bmphead, 14, &br);         //写bmp格式的文件头
    res |= f_write(&fsrc, &bmpheadinfo, 40, &br);   //写bmp格式文件的信息头
    res |= f_write(&fsrc, &rgbquad, 1024, &br);       //写调色板
   
//    for(i=0; i<image_height; i++)
//    {               
//            res = f_write(&fsrc, &buf, image_width , &br);               //写入图像数组的一行数据,长度为图像列数,循环次数为图像行数
//    }
       for(i=0; i<80; i++)
    {            
         res = f_write(&fsrc, &buf, 120, &br);               //写入图像数组的一行数据,长度为图像列数,循环次数为图像行数

        }

    f_close(&fsrc);   
    f_mount(0, 0);      
}
页: [1]
查看完整版本: stm32f103sd卡存储图片问题