在.bmp图像文件中读取深度值时出现问题。 [英] Problem reading depth value in a .bmp image file.

查看:97
本文介绍了在.bmp图像文件中读取深度值时出现问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我写了一个函数,我已经在这里谈过了,应该在一个数组中保存bmp图像文件的每个像素值,但现在我遇到了一个新问题。如果我给我的函数一个我自己制作的bmp图像的路径,我得到深度值'0',而不是'8',这是我保存图像的深度值。但是,如果我尝试在不是由我制作的图像上读取这个值,那就没关系。有人可以帮帮我吗?

这是我的代码函数:

Hi everybody, I wrote a function, which I already talked of here, that should save in an array each pixel value of a bmp image file, but now I have a new problem. If I give to my function a path for a bmp image I made by myself I get as depth value '0', instead of '8', that is the depth value I saved my image with. But if I try to read this value on an image not made by me, it's alright. Can anybody help me?
This is my code function:

void get_pixels(char path[]){
FILE *fp;
int i, j=0, dim=0, count=0;
int offset;
unsigned char depth=NULL;
char bmp[5];
	
	fp = fopen(path, "rb");
	
	for(i=strlen(path)-4;i<strlen(path);i++){
		bmp[j]=path[i];
		j++;
	}
	if(strstr(bmp, ".bmp")==NULL){
		printf("\nIndicare un file .bmp come immagine!\n");
		exit(1);
	}
	
	fseek(fp, 28, SEEK_SET);
	fread(&depth, sizeof(depth), 1, fp);
	printf("\n%d", depth);
	
	if(depth!=8){
		printf("\nSelezionare una immagine a 8 bit!\n");
		exit(2);
	}
	
	fseek(fp, 10, SEEK_SET);
	fread(&offset, sizeof(offset), 1, fp);

	dim=(4-(ima_lar % 4))+ima_lar;
	j=0;
	fseek(fp, offset, SEEK_SET);
	for(i=0;i<ima_alt*dim;i++){
		if(count!=ima_lar){
			fread(&pixels[j], sizeof(char), 1, fp);
			printf("\n%d: %d", j+1, pixels[j]);
			j++;
			count++;
		}else{
			fseek(fp, 1, SEEK_CUR);
			count=0;
		}
	}
	fclose(fp);
}



路径通过'filenames [i]'形式的字符串数组传递给for cicle中的函数。


path is passed to the function in a for cicle, through a string array in the form of 'filenames[i]'.

推荐答案

标准位图有7个不同版本(几乎适用于所有OS / 2和Windows版本),因此DIB部分可以不同,具体取决于用于创建它的应用程序。

这意味着并非所有格式的深度信息都准确地位于第2​​8位......

http://en.wikipedia.org/wiki/BMP_file_format [ ^ ]

了解更多信息: http://www.fileformat.info/format/bmp/egff.htm#MICBMP-DMYID.3 [ ^ ]
The 'standard' bitmap have 7 different versions (for almost every OS/2 and Windows version), so the DIB section can be different, depending on the application used to create it.
That means that not in all format depth info will be exactly at position 28...
http://en.wikipedia.org/wiki/BMP_file_format[^]
Find you more: http://www.fileformat.info/format/bmp/egff.htm#MICBMP-DMYID.3[^]


这篇关于在.bmp图像文件中读取深度值时出现问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆