资源简介
用C语言写个应用程序(命令行运行的就行)提取24bit bmp图像数据,以RGB888保存成图像数组
代码片段和文件信息
#include “Bitmap.h“
FILE *hFile = NULL;
int LoadBitmapFile ( char *fileName BITMAP_IMAGE_PTR bitmap )
{
int hImageFile = 0; // the file stream of the bitmap file
unsigned char *workingBuffer = 0; // use to hold the data
// Open the bitmap file
hImageFile = _open ( fileName _O_RDONLY );
if ( !hImageFile )
{
WriteLogFile ( “LoadBitmapFile function error! \nCan not open the bitmap.\n“ );
return 0;
}// End If
// Read the header portion of the bitmap file
_read ( hImageFile &bitmap->bitmapHeader sizeof ( BITMAP_HEADER ) );
// test if it is a bitmap
if ( bitmap->bitmapHeader.uiType != UNIVERSAL_BITMAP_ID )
{
WriteLogFile ( “LoadBitmapFile function error! \n\t this not a bitmap.\n%s\n“ fileName );
_close ( hImageFile );
return 0;
}// End If
// Read the info portion of the bitmap file
_read ( hImageFile &bitmap->bitmapInformation sizeof ( BITMAP_INFORMATION ) );
// load the data itself now move the file pointer to the data region
// move back from the end of the file offset is set to the size of the specified image
_lseek ( hImageFile -(int)(bitmap->bitmapInformation.biSizeImage) SEEK_END );
// load the data into buffer
workingBuffer = (unsigned char*)malloc ( bitmap->bitmapInformation.biSizeImage );
bitmap->pixelData = (unsigned char*)malloc ( bitmap->bitmapInformation.biSizeImage );
ZeroMemory ( bitmap->pixelData bitmap->bitmapInformation.biSizeImage );
if ( !workingBuffer || !bitmap->pixelData )
{
WriteLogFile ( “LoadBitmapFile function error! \n\tCan not allocate memory for the buffer \n“ );
_close ( hImageFile );
return 0;
}// End If
_read ( hImageFile workingBuffer bitmap->bitmapInformation.biSizeImage );
// now extract the data
long width = bitmap->bitmapInformation.biWidth;
long height = bitmap->bitmapInformation.biHeight;
unsigned long int dwBit = bitmap->bitmapInformation.biBitCount;
long bytesPerLine = (width*(bitmap->bitmapInformation.biBitCount/8) + 3) & (~3);
// Test if the bitmap is avaiable or not
if ( dwBit != 24 && dwBit != 32 )
{
WriteLogFile ( “LoadBitmapFile function error! \n%s\tDo not support this kind of bitmap \n“ fileName );
_close ( hImageFile );
free ( workingBuffer );
free ( bitmap->pixelData );
return 0;
}// End If
// Flip the image
for ( int y = 0; y < height; y++ )
{
memcpy ( &bitmap->pixelData[y*bytesPerLine]
&workingBuffer[(height-1-y)*bytesPerLine]
bytesPerLine );
}// End For ( Each line )
_close ( hImageFile );
free ( workingBuffer );
WriteLogFile ( “%s has been loaded successfully! \n“ fileName );
return 1;
}
void WriteLogFile ( char *content ... )
{
char buffer[1024] = {0}; // the working buffer
va_list argumentList = NULL; //variable of the argument list
if ( !hFile || !content )
return ;
va_start ( argumentList content );
vsprintf ( buffer content argumentList );
- 上一篇:自适应积分算法用于对函数积分
- 下一篇:C语言数据结构迷宫求解的源码
相关资源
- C语言数据结构迷宫求解的源码
- 谭浩强c语言word版
- 聊天+传送文件+设置字体及颜色vs201
- C语言实现malloc和free
- C语言经典程序设计源代码之画图软件
- 进程的同步与互斥C语言
- socket文件传输C++
- 基于huffman编码的文件解压缩程序(
- C语言电子表格
- 用c++设计一个日期类Date,包括年、月
- VC++ 实现增大可执行文件的体积 自
- C语言linux实现ls功能
- 一个完整的des算法的c语言实现
- c语言RSA算法 这是一个完整的rsa算法
- tftp服务器源码,纯c语言
- 严蔚敏《数据结构》的全部代码实现
- LinuxC语言实现CP命令(edsionte.com)
- c++ primer plus 第6版 中文版pdf 高清完整
- C语言指针详解__ppt文件
- FTP客户端程序,c语言编写
- VC写的数字时钟小程序
- C++跑酷游戏
- C++简单的画图程序源代码
- 发送tcp数据包实验设计
- c++ builder实现文件粉碎机的源码
- C语言N皇后打印图形版
- PQ分解法电力系统潮流计算c#版本
- 简单电子英汉词典c++
- Head First_深入浅出C语言(中文版)_带
- C++程序设计语言:第1~3部分原书第4版
评论
共有 条评论