[ACCEPTED]-Get dimensions of JPEG in C++-openvms
You have this C function which may extract the relevant 11 data for you.
This is a C routine but should 10 compile fine with C++.
Pass it a normal 9 FILE pointer (from fopen) to the beginning 8 of a jpeg file and two int pointers to be 7 set with the image height and width.
Or 6 you may find in the Boost library a jpeg class which 5 has the right function (From Adobe Generic Image Library).
boost::gil::jpeg_read_dimensions (const char *filename)
Returns 4 the width and height of the JPEG file at 3 the specified location. Throws std::ios_base::failure 2 if the location does not correspond to a 1 valid JPEG file.
libjpeg is reasonably small, open source 3 and available on OpenVMS. It's probably 2 quicker to install it than to handle JPEG 1 yourself.
No need for full libjpeg library just to 6 get this information (unless you need to 5 do something else with the images). ImageInfo might 4 help you. It is a Java class, but there 3 are ports for other languages, including 2 C++.
As pointed out, Exif might change these 1 information (eg. with orientation setting).
You may want to try GDAL library which serves 8 as an abstraction layer for large number 7 of raster data formats, mostly used in geospatial 6 applications for GIS/RS.
GDAL provides number 5 of APIs, for C, C++ and scripting languages. Of 4 course, it supports JPEG images and its variants 3 like JPEG2000 and more.
Here is a very simple example 2 how to open JPEG image and query its dimensions:
#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();
Check 1 GDAL API tutorial for more complete example.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.