【发布时间】:2014-05-25 07:08:37
【问题描述】:
我已将 JPEG 格式读入 char 数组
char* FileName = "NewI.jpg";
FILE* ImageFile = fopen(FileName, "rb");
if (!ImageFile) {
return -1;
}
fseek(ImageFile, 0, SEEK_END);
unsigned long int FileLength = ftell(ImageFile);
fseek(ImageFile, 0, SEEK_SET);
char* Bytes = (char*)malloc(FileLength * sizeof(char));
fread(Bytes, FileLength, sizeof(unsigned char), ImageFile);
fclose(ImageFile);
如何获得每个像素的 RGB?
【问题讨论】:
-
你没有,反正没那么容易。请记住,JPEG 图像已压缩,因此您必须首先正确解码数据。这不是微不足道的,而且有图书馆为此是有原因的。
-
你确实应该试试图书馆。查看 libjpeg、FreeImage 或类似库
-
您也可以将 jpeg 文件加载到您喜欢的绘图程序中,并将其保存为 bmp 文件。 BMP 文件未压缩,因此更容易提取 RGB 值。
-
律师模式开启:即使是 BMP 也可能包含压缩数据。理论上...
-
@deviantfan 是的,理论上...但大多数绘图程序都相当实用:)