Click here to Skip to main content
15,884,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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;
}
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900