Get JPEG sizes in C ++

I need to get JPEG image sizes in C ++. I am looking for either a fairly simple way to do this, or a small library that provides this functionality. I work in C ++ on OpenVMS, so any external libraries may need to be adapted for compilation on our systems, so please do not send me links to large closed source libraries!

Has anyone come across anything that could do the trick, or understand the JPEG file format (I think I probably mean the JFIF file format here) to tell me how I can run my own solution?

+5
source share
6 answers

You have a C function that can extract the data you need.

This is a C routine, but must be compiled using C ++.
Pass it a regular FILE pointer (from fopen) to the top of the jpeg file and two int pointers that should be set with the height and width of the image.

Or you can find the jpeg class in the Boost library that has the correct function (From Adobe General Image Library ).

jpeg_read_dimensions

boost::gil::jpeg_read_dimensions (const char *filename)

Returns the width and height of the JPEG file at the specified location. Throws std :: ios_base :: crash if the location does not match a valid JPEG file.

+13
source

libjpeg , OpenVMS. , , JPEG.

+3
+2
+1

libjpeg, ( - ). ImageInfo . Java, , ++.
, Exif (, ).

+1

GDAL , , /RS.

GDAL API, C, ++ . , JPEG , JPEG2000 ..

, JPEG :

#include <gdal_priv.h>

GDALAllRegister(); // call ones in your application

GDALDataset* ds = (GDALDataset*)GDALOpen("my.jpeg", GA_ReadOnly);
int width  = ds->GetRasterXSize();
int height = ds->GetRasterYSize(),
int nbands = ds->GetRasterCount();

API GDAL .

+1

All Articles