日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言 写出raw文件,求指导,如何用c语言实现读取*.raw格式图像

發(fā)布時間:2024/10/5 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言 写出raw文件,求指导,如何用c语言实现读取*.raw格式图像 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓

/*

** 這個程序是讀取jpg圖像的

** 后續(xù)加上jpg圖像打開和存放

*/ #include

#include

#include

#include

#include #define SOI 0xD8 //文件頭

#define EOI 0xD9 //文件尾

#define APP0 0xE0 //定義交換格式和圖像識別信息

#define SOF0 0xC0 //幀開始(標準 JPEG)

#define DQT 0xDB //定義量化表

#define DHT 0xC4 //定義 Huffman 表(霍夫曼表)

#define SOS 0xDA // 掃描行開始

#define DRI 0xDD //定義重新開始間隔

#define COM 0xFE //注釋 unsigned short jpgWidth; //圖像的寬

unsigned short jpgHeight; //圖像的高

unsigned char bitDepth; //圖像類型,每像素位數(shù)

unsigned short jpgXpelsPerMeter; //水平分辨率

unsigned short jpgYpelsPerMeter; //垂直分辨率

unsigned char SOF_find=0; char readPath[100]; //圖像路徑

unsigned char CurrentByte; //當前字節(jié)

unsigned short CurrentWord; //當前word

unsigned int BytePos; //當前字節(jié)的位置 bool readjpg(char *jpgName); //讀取路徑

void showjpg(); //顯示

void GetJpgSize(FILE *fp); //獲取大小 /****************************分割線**************************************/

bool readjpg(char *jpgName)

{

unsigned char Flag_1,Flag_2; //文件頭 FFD8

unsigned short Xdensity,Ydensity;

/*unsigned char SOS_find=0;

unsigned int FileLength;

unsigned char Length;*/

//二進制讀方式打開指定的圖像文件

FILE *fp;

fp=fopen(jpgName,"rb");

if(fp==0)

{

perror("jpgName"); //提示錯誤信息

getch();

exit(EXIT_FAILURE); //出現(xiàn)錯誤,終止程序。

} /*

判斷文件類型是否為JPG

檢查第1, 2字節(jié)

*/

fread(&Flag_1,1,1,fp);

fseek(fp,1L,0);

fread(&Flag_2,1,1,fp);

if(( Flag_1 != 0xff) || (Flag_2 != 0xd8) )

{

printf("Not a jpg file?? (SOI)\n");

exit(EXIT_FAILURE);

}

//開始尋找開始位置

GetJpgSize(fp); fclose(fp);

return 1;

} void showjpg()

{

//窗口大小為圖片大小

initgraph(jpgWidth,jpgHeight+40);

setbkcolor(WHITE);

setcolor(BLACK);

cleardevice(); setfont(16, 8, "宋體");

char width[5],height[5];

sprintf(width, "%d",jpgWidth);

sprintf(height, "%d",jpgHeight); outtextxy(0,0,"圖像的寬:");

outtextxy(10+textwidth("圖像的寬:"),0,width); outtextxy(jpgWidth/2,0,"圖像的高:");

outtextxy(jpgWidth/2 + 10 + textwidth("圖像的高"),0,height); IMAGE img; // 定義 IMAGE 對象

loadimage(&img, readPath); //讀取圖片到 img 對象中

putimage(0, 40, &img); // 在坐標 (0, 0) 位置顯示 IMAGE 對象 getch();

closegraph();

} //獲取照片尺寸大小

void GetJpgSize(FILE *fp)

{ unsigned char HeightH;

unsigned char HeightL;

unsigned char WidthH;

unsigned char WidthL;

unsigned char BitDepth;

while(!SOF_find)

{

CurrentByte=fgetc(fp);

if(CurrentByte!=0xFF)

continue;

//發(fā)現(xiàn)標記符

CurrentByte=fgetc(fp);

switch(CurrentByte)

{

case APP0: break;

case SOF0:

fseek(fp,2L,1); BitDepth=fgetc(fp); //圖像高的高位和低位

HeightH=fgetc(fp); HeightL=fgetc(fp); //圖像寬的高位和低位

WidthH=fgetc(fp); WidthL=fgetc(fp); SOF_find=1;

break;

default:

break;

}

}

jpgHeight=HeightH * 256 + HeightL;

jpgWidth=WidthH * 256 + WidthL; } void main()

{

printf("輸入圖像的完整路徑及文件名:\n");

gets(readPath);

readjpg(readPath);

printf(" bitDepth=%x\n height=%x\n width=%x\n ",bitDepth,jpgHeight,jpgWidth);

printf(" jpgXpelsPerMeter=%x\n jpgYpelsPerMeter=%x\n",jpgXpelsPerMeter,jpgYpelsPerMeter); printf("按任意鍵顯示圖像\n");

getch();

showjpg();

}

總結(jié)

以上是生活随笔為你收集整理的c语言 写出raw文件,求指导,如何用c语言实现读取*.raw格式图像的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。