打印

bmp图片

[复制链接]
236|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
博斯|  楼主 | 2019-11-27 18:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大神们,帮我看看这程序,我一直显示不出图片,我检查了几遍都没发现问题
程序为: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

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

412

主题

412

帖子

0

粉丝