4 回答

TA貢獻1793條經驗 獲得超6個贊
數據在黑屏下顯示數據量會很大,故存為dat文件;
#include <windows.h>
#include <stdio.h>
/*
輸入的指令必須如下格式: command xx.bmp width height
command 編譯之后的程序名稱
xx.bmp 需要獲取像素值的bmp文件名,需輸入擴展名
width,height bmp文件的大小
*/
int main(int argc,char* argv[])
{
int x,y,i;
unsigned char *px;
HBITMAP map;
FILE* pout;
x=atoi(argv[2]);//得到bmp文件的大小信息
y=atoi(argv[3]);
px=new unsigned char[x*y];
map=(HBITMAP)LoadImage(NULL,argv[1],IMAGE_BITMAP,x,y,LR_LOADFROMFILE);//裝載bmp文件
GetBitmapBits(map,x*y,px);//獲取像素值信息
pout=fopen("pixeldata.dat","wb");
for(i=0;i<x*y;i++)
{
if((i%4)!=3)//因為bmp文件為每個像素分配了4Byte的空間,分別為R,G,B,保留,估輸出時不寫出第四個Byte的值(必為0)
fwrite(&px[i],sizeof(unsigned char),1,pout);
}
fclose(pout);
return 0;
}
- 4 回答
- 0 關注
- 1050 瀏覽
添加回答
舉報