jeffreyg
asked on
Finding the image dimensions of a file without reading it
Guys,
I am wanting to find the dimensions of a image quickly. Now I know that there is a BITMAPFILEHEADER structure which can allow me to read the portion of the bitmap I want to read to get the width and height of the image.
-----
CFile file;
// sBMPFileName is the BMP filename
if( !file.Open( sBMPFileName, CFile::modeRead) )
return ;
BITMAPFILEHEADER bmfHeader;
// Read file header
if (file.Read((LPSTR)&bmfHead er, sizeof(bmfHeader)) != sizeof(bmfHeader))
return ;
// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return ;
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHead er, sizeof(bmiHeader)) != sizeof(bmiHeader))
return ;
int bmWidth = bmiHeader.biWidth;
int bmHeight = bmiHeader.biHeight;
------
I want to be able to do this for all images. I have potentially thousands of images and the system need to perform an add of an image size e.g. 6x4" print from the file. I want to make sure that the image is off sufficient quality to allow reasonable printing quality.
Is there something similar to this in mfc / gdi+ to do the same thing for all image types .... jpg, bmp, tiff, pcx.
regards,
Gordon.
I am wanting to find the dimensions of a image quickly. Now I know that there is a BITMAPFILEHEADER structure which can allow me to read the portion of the bitmap I want to read to get the width and height of the image.
-----
CFile file;
// sBMPFileName is the BMP filename
if( !file.Open( sBMPFileName, CFile::modeRead) )
return ;
BITMAPFILEHEADER bmfHeader;
// Read file header
if (file.Read((LPSTR)&bmfHead
return ;
// File type should be 'BM'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return ;
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHead
return ;
int bmWidth = bmiHeader.biWidth;
int bmHeight = bmiHeader.biHeight;
------
I want to be able to do this for all images. I have potentially thousands of images and the system need to perform an add of an image size e.g. 6x4" print from the file. I want to make sure that the image is off sufficient quality to allow reasonable printing quality.
Is there something similar to this in mfc / gdi+ to do the same thing for all image types .... jpg, bmp, tiff, pcx.
regards,
Gordon.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
P.S. I want to load all image types esp. jpg, bmp, tiff, gif.
regards,
Gordon.
regards,
Gordon.
ASKER
Thanx Alex,
Best method I could find. It'll have to do.
:))
Best method I could find. It'll have to do.
:))
ASKER
I am using that already, for images that I display on the screen (12 thumbnails). I do what you suggest already.
1. Find out how many images there are in the directory I am in, by using CFileFind.
2. Create a linked list of placeholders for all the files.
3. Load the first 12 images in with the Bitmap::FromFile() function.
4. Don't load any more images atm, what if the user wants only the first image in a list of 2000 images?
5. If the user wants to view the next 12 images repeat process 3.
6. If the user clicks the select all images for a 6x4 print, load all the images that fulfill this criteria.
Now if the user does step 6 without loading all the images I don't know the image dimension.
Ideally when create my liked list of placeholders in step 2 I want to get the header information of the each image only.
regards,
Gordon.