Click here to Skip to main content
12,073,837 members (64,702 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4.3K views
13 bookmarked
Posted

Image Converter

, 17 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Quick tool to convert batch PNG images to ICO format

Introduction

Image Converter (includes source code) is a free tool to convert between different image formats; it is based on CxImage class developed by Davide Pizzolato. I used it to convert PNG files from 1000+ Free “Farm-Fresh Web Icons” library to icons.

Image Converter

Using the code

The main processing is done in ConvertImage function:.

void CImageConverterDlg::ConvertImage(CString strFilePath)
{
	CString strMessage, strType = _T(".ico");
	m_ctrlFormat.GetWindowText(strType);

	m_nCurrentIcon = m_nDefaultIcon;

	TCHAR lpszDrive[_MAX_DRIVE];
	TCHAR lpszDirectory[_MAX_DIR];
	TCHAR lpszFilename[_MAX_FNAME];
	TCHAR lpszExtension[_MAX_EXT];

	VERIFY(0 == _tsplitpath_s(strFilePath, lpszDrive, _MAX_DRIVE, lpszDirectory, _MAX_DIR, lpszFilename, _MAX_FNAME, lpszExtension, _MAX_EXT));
	CString strConverted = m_strOutputFolder + lpszFilename + strType;

	CxImage pImage(strFilePath, GetTypeIdFromExt(lpszExtension));
	if (pImage.IsValid())
	{
		if (pImage.Save(strConverted, GetTypeIdFromExt(strType)))
		{
			pImage.Resample(16, 16);

			CBitmap* pBitmap = CBitmap::FromHandle(pImage.MakeBitmap());
			m_nCurrentIcon = m_pImageList.Add(pBitmap, RGB(0x00, 0x00, 0x00));

			strMessage.Format(_T("%s%s has been converted to %s%s ..."), lpszFilename, lpszExtension, lpszFilename, strType);
			DisplayMessage(m_nCurrentIcon, strMessage);
			m_nImageCounter++;
		}
	}
}

History

version 1.4 (August 18th, 2014) - Initial release.

License

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

Share

About the Author

Mihai MOGA
Architect Printec Group Romania SRL
Romania Romania
My professional background includes knowledge of analyst programmer for Microsoft Visual C++, Microsoft Visual C#, Microsoft Visual Basic, Sun Java, assembly for Intel 80x86 microprocessors, assembly for PIC microcontrollers (produced by Microchip Inc.), relational databases (MySQL, Oracle, SQL Server), concurrent version systems, bug tracking systems, web design (XHTML, CSS, XML, PHP/MySQL, JavaScript, Flash).

If you like my articles, please visit my website for more: http://www.mihaimoga.com/

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 18 Aug 2014
Article Copyright 2014 by Mihai MOGA
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid