[英]How to check whether a jpeg is a RGB or CMYK format?
我正在使用c ++,gdi +,WINDOWS。 如何检查jpeg是RGB还是CMYK?
如果使用IJG libjpeg库,则可以打开JPEG文件,读取标头,然后查看它是灰度(单色),RGB还是CMYK。 (实际上,有几个免费的JPEG库,但是IJG libjpeg可能是最常用的库。)您可以在以下位置找到libjpeg源:
http://www.ijg.org/files/jpegsrc.v8c.tar.gz
如何读取标头的大致示例如下:
struct jpeg_decompress_struct dinfo;
FILE* file = fopen(fname, "r");
/* Step 1: allocate and initialize JPEG decompression object */
jpeg_create_decompress(&dinfo);
/* Step 2: specify data source (eg, a file) */
jpeg_stdio_src(&dinfo, file);
/* Step 3: read file parameters with jpeg_read_header() */
(void) jpeg_read_header(dinfo, TRUE);
/* Step 4: set parameters for decompression
* In this example, we don't need to change any of the
* defaults set by jpeg_read_header(), so we do nothing here.
*/
if (dinfo->jpeg_color_space == JCS_CMYK || dinfo->jpeg_color_space == JCS_YCCK) {
// CMYK
} else if (dinfo->jpeg_color_space == JCS_RGB || dinfo->jpeg_color_space == JCS_YCbCr) {
// RGB
} else if (dinfo->jpeg_color_space == JCS_GRAYSCALE) {
// Grayscale
} else {
ERREXIT(dinfo, JERR_CONVERSION_NOTIMPL);
// error condition here...
}
/* You can skip the other steps involved in decompressing an image */
/* Step 8: Release JPEG decompression object */
jpeg_destroy_decompress(dinfo);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.