野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14337|回复: 5

bmp图片

[复制链接]
发表于 2015-4-10 23:04:46 | 显示全部楼层 |阅读模式
大神们,帮我看看这程序,我一直显示不出图片,我检查了几遍都没发现问题
程序为:bsp_bm.c和bsp_bm.h

bsp_bm.c为
#include "bsp_bmp.h"
#include "bsp_ili9341.h"
#include "ff.h"
//#include "bsp_usart1.h"

FATFS bmpfs[2];
FIL   bmpfsrc,bmpfdst;
BYTE  pColorData[960];
FRESULT bmpres;

#define RGB24TORGB16(R,G,B) ((unsigned short int)((((R)>>3)<<11) | (((G)>>2)<<5)        | ((B)>>3)))



void LCD_Show_Bmp(unsigned short int x,unsigned short int y,unsigned char *pic_name)
{
        int height,width,l_width;
        int i,j,k;
        unsigned int read_num;
        unsigned char temp_name[20];
       
        BITMAPFILEHEADER bitheader;
        BITMAPINFOHEADER bitinfoheader;
        BYTE red,green,blue;
        WORD filetype;
       
        sprintf((char*)temp_name,"0:%s",pic_name);
       
        f_mount(0,&bmpfs[0]);  
       
        bmpres=f_open(&bmpfsrc,(char *)temp_name,FA_OPEN_EXISTING|FA_READ);
       
        if(bmpres ==FR_OK)
                {
                        printf("\r\ngood");
                        f_read(&bmpfsrc,&filetype,sizeof(WORD),&read_num);
                        f_read(&bmpfsrc,&bitheader,sizeof(tagBITMAPFILEHEADER),&read_num);
                        f_read(&bmpfsrc,&bitinfoheader,sizeof(BITMAPINFOHEADER),&read_num);
                }
        else
        {
                        return;
        }
                height=bitinfoheader.biHeight;
                width =bitinfoheader.biWidth;
                l_width=WIDTHBYTES(width*(bitinfoheader.biBitCount));
               
                if(l_width>960)
                {
                        return;
                }
               
                LCD_GramScan(3);
               
                LCD_OpenWindows(x,y,width,height);
                       
                if(bitinfoheader.biBitCount >=24)
                {
                        printf("\r\ngood1");
                                for(i=0;i<height;i++)
                        {
//                        f_read(&bmpfsrc,pColorData,l_width/2,&read_num);
//                        f_read(&bmpfsrc,pColorData+l_width/2,l_width/2,&read_num);
                                        f_read(&bmpfsrc,pColorData,l_width,&read_num);
                                                for(j=0;j<width;j++)
                                                        {  
                                                                  k=j*3;
                                                                        red   =pColorData[k+2];
                                                                  green =pColorData[k+1];
                                                                        blue  =pColorData[k];
//                                                          printf("0x%x0x%x0x%x",pColorData[k],pColorData[k+1],pColorData[k+2]);
                                                                        LCD_WR_Data(RGB24TORGB16(red,green,blue));
                                                        }
                        }
                       
                }
                f_close(&bmpfsrc);
       
}


bsp_bm.h为
#ifndef __BSP_BMP_H
#define __BSP_BMP_H


#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef unsigned char  BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef long LONG;


#define WIDTHBYTES(bits)     (((bits)+31)/32*4)


typedef struct   tagBITMAPFILEHEADER
{
        DWORD bfSize;
        WORD  bfReserved1;
        WORD  bfReserved2;
        DWORD bfOffBits;
}BITMAPFILEHEADER,tagBITMAPFILEHEADER;


typedef struct tagBITMAPINFOHEADER
{
        DWORD biSize;
        LONG  biWidth;
        LONG  biHeight;
        WORD  biPlanes;
        WORD  biBitCount;
        DWORD biCompression;
        DWORD biSizeImage;
        LONG  biXPelsPerMeter;
        LONG  biYPelsPerMeter;
        DWORD biClrUsed;
        DWORD biClrImportant;
       
}BITMAPINFOHEADER,tagBITMAPINFOHEADER;


void LCD_Show_Bmp(unsigned short int x,unsigned short int y,unsigned char *pic_name);




#endif




捕获.PNG
回复

使用道具 举报

发表于 2015-4-11 09:08:37 | 显示全部楼层
Lcd_show_bigbmp(0, 0,"/wildfire.bmp");
Lcd_show_bmp( 10,10,"/pic1.bmp");               
Lcd_show_bmp( 170,0,"/pic2.bmp");
标示地址的斜线反了
如果在根目录下,可以省去
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-11 12:56:26 | 显示全部楼层
在根目录,省去还是显示不出来
回复 支持 反对

使用道具 举报

发表于 2015-4-12 11:10:29 | 显示全部楼层
中文可以正常显示吗
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-12 14:30:00 | 显示全部楼层
中文,英语都可以正常显示

回复 支持 反对

使用道具 举报

发表于 2015-4-13 16:34:15 | 显示全部楼层
bmp.rar (3.24 KB, 下载次数: 29)
换这个bmp驱动函数看看
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-23 15:31 , Processed in 0.048822 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表