Click here to Skip to main content
12,505,104 members (63,699 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
Hello guys

Is there any way to check if downloaded image(.TIFF,.PNG,.JPEG and others) has compression or not ?
Currently I'm using OpenCV, but I don't care how to retrieve this info.

If I open some image via ordinary Windows Explorer->Right button click->Properties->Details->and we all can see a "compression" field

Thnx
Posted 6-Oct-12 3:58am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

To retrieve "compression" field like Windows Explorer->Right button click->Properties->Details
You have to use GdiPlus library:
1. Create Image class object (http://msdn.microsoft.com/en-us/library/windows/desktop/ms534462(v=vs.85).aspx[^])
2. Get compression method (PropertyTagCompression) from image metadata calling Image.GetPropertyItem method (http://msdn.microsoft.com/en-us/library/windows/desktop/ms535390(v=vs.85).aspx[^])
3. Compare returned value with possible discrete values for PKEY_Image_Compression (IMAGE_COMPRESSION_*) declared in propkey.h

Code example:
#include <windows.h>
#include <gdiplus.h>
#include <propkey.h>
 
using namespace Gdiplus;
 
BOOL GetCompressionMethod(
	PWSTR			pwszImage,
	PUSHORT			pusCompresssionMethod)
{
	GdiplusStartupInput	StartupInput;
	ULONG_PTR		Token;
	Image			*pImage;
	UINT			uiSize;
	PropertyItem		*pItem;
	Status			Result;
 
	GdiplusStartup(&Token, &StartupInput, NULL);
 
	pImage = new Image(pwszImage);
	if (pImage == NULL)
	{
		GdiplusShutdown(Token);
 
		return FALSE;
	}
 
	uiSize = pImage->GetPropertyItemSize(
		PropertyTagCompression);
	if (uiSize == 0)
	{
		delete pImage;
		GdiplusShutdown(Token);
 
		return FALSE;
	}
 
	pItem = (PropertyItem *) new BYTE [uiSize];
	if (pItem == NULL)
	{
		delete pImage;
		GdiplusShutdown(Token);
 
		return FALSE;
	}
 
	Result = pImage->GetPropertyItem(
		PropertyTagCompression, uiSize, pItem);
	if (Result != Ok)
	{
		delete [] ((PBYTE) pItem);
		delete pImage;
		GdiplusShutdown(Token);
 
		return FALSE;
	}
 
	*pusCompresssionMethod = *(PUSHORT) pItem->value;
 
	switch (*(PUSHORT) pItem->value)
	{
	case IMAGE_COMPRESSION_UNCOMPRESSED:
		// YourCode
		break;
	case IMAGE_COMPRESSION_CCITT_T3:
		// YourCode
		break;
	case IMAGE_COMPRESSION_CCITT_T4:
		// YourCode
		break;
	case IMAGE_COMPRESSION_CCITT_T6:
		// YourCode
		break;
	case IMAGE_COMPRESSION_LZW:
		// YourCode
		break;
	case IMAGE_COMPRESSION_JPEG:
		// YourCode
		break;
	case IMAGE_COMPRESSION_PACKBITS:
		// YourCode
		break;
	}
 
	delete [] ((PBYTE) pItem);
	delete pImage;
	GdiplusShutdown(Token);
 
	return TRUE;
}
  Permalink  
v2
Comments
JOHN 602 7-Oct-12 9:20am
   
Oh dude thanks a lot. I've been thinking that I'd never find the way how to do it.

О,чувак, спасибо. А то я думал никогда уже с этой шнягой не разберусь.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100