/// Receives the MIME type of an encoder and returns the class identifier (CLSID) of that encoder.
/// The MIME types of the encoders built into Windows GDI+ are as follows: image/bmp, image/jpeg, image/gif, image/tiff, image/png.
/// \param[in]	format		The mime-type format of the CLSID to get.
/// \param[out]	pClsid		A pointer to the CLSID to fill.
/// \return the index of the ImageCodecInfo object if success, -1 if failure
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
	UINT  num = 0;          // number of image encoders
	UINT  size = 0;         // size of the image encoder array in bytes

	Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;

	Gdiplus::GetImageEncodersSize(&num, &size);
	if(size == 0)
		return -1;  // Failure

	pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
	if(pImageCodecInfo == NULL)
		return -1;  // Failure

	GetImageEncoders(num, size, pImageCodecInfo);

	for(UINT j = 0; j < num; ++j)
	{
		if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
		{
			*pClsid = pImageCodecInfo[j].Clsid;
			free(pImageCodecInfo);
			return j;  // Success
		}    
	}

	free(pImageCodecInfo);
	return -1;  // Failure
}
Example #2
0
int CGdiPlusImage::GetEncoderClsid(LPCTSTR format, CLSID* pClsid)
{
	UINT  num = 0;          
	UINT  size = 0;        

	ImageCodecInfo* pImageCodecInfo = NULL;   

	GetImageEncodersSize(&num, &size);   
	if(size == 0)   
		return -1;  

	pImageCodecInfo = (ImageCodecInfo*)(malloc(size));   
	if(pImageCodecInfo == NULL)   
		return -1;  

	GetImageEncoders(num, size, pImageCodecInfo);   

	for(UINT j = 0; j < num; ++j)   
	{   
		if( StrCmp(pImageCodecInfo[j].MimeType, format) == 0 )   
		{   
			*pClsid = pImageCodecInfo[j].Clsid;   
			free(pImageCodecInfo);   
			return j; 
		}       
	}   

	free(pImageCodecInfo);   
	return -1;  
}
BOOL CCBitmapConvert::GetImageCLSID(const WCHAR* format, CLSID* pCLSID)
{
	UINT num = 0;
	UINT size = 0;
	ImageCodecInfo* pImageCodecInfo = NULL;
	GetImageEncodersSize(&num, &size);
	if(size == 0)
	{
		return FALSE;
	}
	pImageCodecInfo = (ImageCodecInfo *)malloc((size));
	if(pImageCodecInfo == NULL)
		return FALSE;
	GetImageEncoders(num, size, pImageCodecInfo);
	// Find for the support of format for image in the windows
	for(UINT i = 0; i < num; ++i)
	{
		if( wcscmp(pImageCodecInfo[i].MimeType, format) == 0)
		{
			*pCLSID = pImageCodecInfo[i].Clsid;
			free(pImageCodecInfo);
			return TRUE;
		}
	}
	free(pImageCodecInfo);
	return FALSE;
}
Example #4
0
//이미지 코덱의 CLSID를 가져오는 함수
BOOL CMainFrame::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
	UINT  num = 0;	// 이미지 엔코더 번호
	UINT  size = 0;	// 이미지 엔코더 배열의 사이즈
 
	GetImageEncodersSize(&num, &size); //이미지 엔코더의 사이즈를 구함
	if(size == 0) return FALSE;

	ImageCodecInfo* pImageCodecInfo = NULL;
	pImageCodecInfo = (ImageCodecInfo*)(malloc(size)); //메모리 할당
	if(pImageCodecInfo == NULL) return FALSE;

	GetImageEncoders(num, size, pImageCodecInfo); //코덱정보를 구함
	for(UINT i=0; i < num; ++i)
	{
		//코덱 정보와 전달받은 포맷이 동일할 경우
		if(wcscmp(pImageCodecInfo[i].MimeType, format) == 0 )
		{
			*pClsid = pImageCodecInfo[i].Clsid; //CLSID를 지정
			free(pImageCodecInfo); //메모리 해제
			return TRUE;
		}    
	}
	free(pImageCodecInfo);
	return FALSE;
}
Example #5
0
// bmp转jpg
BOOL GDIPluseExt::GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{

	UINT num= 0;
	UINT size= 0;

	ImageCodecInfo* pImageCodecInfo = NULL;

	GetImageEncodersSize(&num, &size);
	if(size== 0)
	{
		return FALSE;
	}
	pImageCodecInfo= (ImageCodecInfo*)(malloc(size));
	if(pImageCodecInfo== NULL)
	{
		return FALSE;
	}

	GetImageEncoders(num, size, pImageCodecInfo);

	for(UINT j=0; j< num; ++j)
	{
		if(wcscmp(pImageCodecInfo[j].MimeType, format)== 0)
		{
			*pClsid= pImageCodecInfo[j].Clsid;
			free(pImageCodecInfo);
			return j;
		}
	} 
	free(pImageCodecInfo);
	return FALSE;
}
Example #6
0
// ** These code from http://www.cnblogs.com/LinuxHunter/archive/2012/07/15/2592015.html
int GetImageCLSID(const WCHAR* format, CLSID* pCLSID)
{
	UINT num = 0;
	UINT size = 0;

	Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
	Gdiplus::GetImageEncodersSize(&num, &size);

	if (size == 0)
		return FALSE; 

	pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
	if (pImageCodecInfo == NULL)
		return FALSE; 

	GetImageEncoders(num, size, pImageCodecInfo);

	for (UINT i = 0; i < num; ++i)
	{
		if (wcscmp(pImageCodecInfo[i].MimeType, format) == 0)
		{
			*pCLSID = pImageCodecInfo[i].Clsid;
			free(pImageCodecInfo);
			return TRUE;
		}
	}

	free(pImageCodecInfo);
	return FALSE;
}
Example #7
0
	void BaseManager::saveImage(int _width, int _height, MyGUI::PixelFormat _format, void* _texture, const std::string& _filename)
	{
		Gdiplus::PixelFormat format;
		int bpp;

		if (_format == MyGUI::PixelFormat::R8G8B8A8)
		{
			bpp = 4;
			format = PixelFormat32bppARGB;
		}
		else if (_format == MyGUI::PixelFormat::R8G8B8)
		{
			bpp = 3;
			format = PixelFormat24bppRGB;
		}
		else if (_format == MyGUI::PixelFormat::L8A8)
		{
			bpp = 2;
			format = PixelFormat16bppGrayScale;
		}
		else
		{
			MYGUI_LOG(Error, "Unsuitable texture format for saving.");
			return;
		}

		UINT num, size;
		Gdiplus::GetImageEncodersSize(&num, &size);

		Gdiplus::ImageCodecInfo* imageCodecInfo = (Gdiplus::ImageCodecInfo*)malloc(size);
		GetImageEncoders(num, size, imageCodecInfo);

		CLSID* pngClsid = NULL;
		for (UINT j = 0; j < num; ++j)
		{
			if (wcscmp(imageCodecInfo[j].MimeType, L"image/png") == 0)
			{
				pngClsid = &imageCodecInfo[j].Clsid;
				break;
			}
		}

		if (pngClsid == NULL)
		{
			MYGUI_LOG(Error, "png codec not found");
			return;
		}

		Gdiplus::Bitmap image(_width, _height, bpp * _width, format, (BYTE*)_texture);

		HRESULT res = image.Save(MyGUI::UString(_filename).asWStr_c_str(), pngClsid, NULL);
		if (res != S_OK)
			MYGUI_LOG(Error, "Texture saving error. result = " << res);
	}
Example #8
0
WINERROR ScrGetEncoderClsid(
	const WCHAR*	format, 
	CLSID*			pClsid
	)
{
	Gdiplus::GdiplusStartupInput input;
	ULONG_PTR token;
	PVOID MemToFree = NULL;
	
	Gdiplus::Status status = Gdiplus::GdiplusStartup(&token, &input, 0);
		
	if (status == Gdiplus::Ok)
	{
		UINT num = 0;
		UINT size = 0;

		Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;

		Gdiplus::GetImageEncodersSize(&num, &size);
		
		if(size == 0)
		{
			return ERROR_UNSUCCESSFULL;
		}

		pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(AppAlloc(size));
		
		if(pImageCodecInfo == NULL)
		{
			return ERROR_UNSUCCESSFULL;
		}

		GetImageEncoders(num, size, pImageCodecInfo);

		for(UINT i = 0; i < num; ++i)
		{
			if(wcscmp(pImageCodecInfo[i].MimeType, format) == 0 )
			{
				MemToFree = (PVOID)pImageCodecInfo;
				*pClsid = pImageCodecInfo[i].Clsid;
				AppFree(MemToFree);
				
				return NO_ERROR;
			}
		}

		MemToFree = (PVOID)pImageCodecInfo;
		AppFree(MemToFree);
	}

	return ERROR_UNSUCCESSFULL;
}
Example #9
0
CLSID GetEncoderClsid(const WCHAR* format) {
    CLSID null = {0};
    UINT numEncoders, size;
    Status ok = GetImageEncodersSize(&numEncoders, &size);
    if (ok != Ok || 0 == size)
        return null;
    ScopedMem<ImageCodecInfo> codecInfo((ImageCodecInfo*)malloc(size));
    if (!codecInfo)
        return null;
    GetImageEncoders(numEncoders, size, codecInfo);
    for (UINT j = 0; j < numEncoders; j++) {
        if (str::Eq(codecInfo[j].MimeType, format)) {
            return codecInfo[j].Clsid;
        }
    }
    return null;
}
Example #10
0
BOOL GdiplusUtilities::CreateThumbnail(LPCTSTR srcFile, LPCTSTR thumbnailFile, ImageFormatEnum imageFormat, INT cx, INT cy)
{
	Gdiplus::Bitmap* pSrcImage = Gdiplus::Bitmap::FromFile(srcFile, FALSE);
	if (pSrcImage == NULL)
		return FALSE;


	//=== Default function...stretches the image
	Gdiplus::Image* pDestImage = pSrcImage->GetThumbnailImage(cx, cy);
	
	delete pSrcImage;

	CLSID pngClsid;

	UINT  num = 0;          // number of image encoders
	UINT  size = 0;         // size of the image encoder array in bytes

	Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;

	Gdiplus::GetImageEncodersSize(&num, &size);
	if(size == 0)
		return -1;  // Failure

	pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
	if(pImageCodecInfo == NULL)
		return -1;  // Failure

	GetImageEncoders(num, size, pImageCodecInfo);

	for(UINT j = 0; j < num; ++j)
	{
		if( wcscmp(pImageCodecInfo[j].MimeType, _T("image/png")) == 0 )
		{
			pngClsid = pImageCodecInfo[j].Clsid;
			free(pImageCodecInfo);
			Gdiplus::Status st = pDestImage->Save(thumbnailFile, &pngClsid, NULL);
			return st == Gdiplus::Ok;
		}    
	}

	free(pImageCodecInfo);
	
	return FALSE;


}
Example #11
0
//=================================================
// Overrides
//=================================================
BOOL CMainDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	// Add "About..." menu item to system menu.
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if(pSysMenu != NULL)
	{
		CString strAboutMenu = _T("About...");
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// Set max-length on edit boxes
	CEdit* pEdit = NULL;
	VERIFY(pEdit = (CEdit*)GetDlgItem(IDC_IMAGE_NAME));
	pEdit->SetLimitText(50);

	// Fill combo with all supported image formats
	CComboBox* pCombo = NULL;
	VERIFY(pCombo = (CComboBox*)GetDlgItem(IDC_IMAGE_EXT));
	ImageCodecInfo* pImageCodecInfo = NULL;
	UINT nCount = 0; // number of image encoders
	UINT nSize = 0;  // size of the image encoder array in bytes
	GetImageEncodersSize(&nCount, &nSize);
	if(nSize > 0)
	{
		pImageCodecInfo = (ImageCodecInfo*)(malloc(nSize));
		if(pImageCodecInfo != NULL)
		{
			GetImageEncoders(nCount, nSize, pImageCodecInfo);
			for(UINT x = 0; x < nCount; x ++)
			{
				CString strFormat(pImageCodecInfo[x].FormatDescription);
				int iItem = pCombo->AddString(strFormat);
				ASSERT(iItem != -1);
				CLSID* pCLSID = new CLSID;
				ASSERT(pCLSID);
				*pCLSID = pImageCodecInfo[x].Clsid;
				pCombo->SetItemData(iItem, (DWORD_PTR)pCLSID);
				
				// JPEG will be our default image type
				if(strFormat.CompareNoCase(_T("jpeg")) == 0)
				{
					m_clsidImgType = pImageCodecInfo[x].Clsid;
					pCombo->SetCurSel(iItem);
				}
			}
			free(pImageCodecInfo);
		}    
	}

	SetControlValues();

	// Start keyboard hook to capture the print screen key
	ActivateKeyboardHook(TRUE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}
Example #12
0
void keyPressed(int vk){
	switch (vk){
	case VK_ESCAPE:
		if (hbitmap != NULL){
			if (selectRect.valid){
				selectRect.valid = false;
			}
			else{
				DeleteObject(hbitmap);
				hbitmap = NULL;
				selectRect.valid = false;
				delete[] capturePixels;
				DeleteObject(buffer);
				ShowWindow(hwnd, SW_HIDE);
			}
		}
		break;
	case VK_RETURN:
		sendToClipboard();
		disposeWindow();
		break;
	case 'C':
		if (ctrlPressed)
			sendToClipboard();
		break;
	case 'X':
		if (ctrlPressed){
			sendToClipboard();
			disposeWindow();
		}
		break;
	case 'S':
		if (ctrlPressed){
			OPENFILENAMEW openFile = { 0 };
			wchar_t filePath[261];
			memset(&filePath, 0, 261);
			openFile.lStructSize = sizeof(OPENFILENAMEA);
			openFile.hwndOwner = hwnd;
			openFile.lpstrFile = filePath;
			openFile.nMaxFile = 261;
			openFile.Flags = OFN_EXPLORER;
			unsigned int num = 0, size = 0;
			GetImageEncodersSize(&num, &size);
			ImageCodecInfo *pImageCodecInfo = (ImageCodecInfo *)(malloc(size));
			GetImageEncoders(num, size, pImageCodecInfo);

			wstring s;
			DWORD index = 0;

			for (unsigned int i = 0; i < num; ++i){
				const wchar_t *format = pImageCodecInfo[i].FormatDescription;
				const wchar_t *filename = pImageCodecInfo[i].FilenameExtension;
				wstring fileLower(filename);
				transform(fileLower.begin(), fileLower.end(), fileLower.begin(), tolower);
				s = s + wstring(format, wcslen(format)) + wstring(L" (") + fileLower + wstring(L")", 2) + wstring(filename, wcslen(filename) + 1);

				if (wcscmp(format, L"PNG") == 0) {
					index = i + 1;
				}
			}
			s = s + wstring(L"\0", 1);

			openFile.lpstrFilter = s.c_str();

			openFile.lpstrCustomFilter = NULL;
			openFile.lpstrFileTitle = NULL;
			openFile.lpstrInitialDir = NULL;
			openFile.lpstrTitle = L"Save Capture As";
			openFile.nFilterIndex = index;
			if (!GetSaveFileNameW(&openFile)){
				return;
			}

			BITMAPINFOHEADER bmih;
			bmih.biSize = sizeof(BITMAPINFOHEADER);
			bmih.biWidth = selectRect.width;
			bmih.biHeight = -selectRect.height;
			bmih.biPlanes = 1;
			bmih.biBitCount = 32;
			bmih.biCompression = BI_RGB;

			BITMAPINFO dbmi;
			dbmi.bmiHeader = bmih;

			HDC hdc = GetDC(NULL);
			HDC hdcMem = CreateCompatibleDC(hdc);
			HBITMAP capture = CreateCompatibleBitmap(hdc, selectRect.width, selectRect.height);
			bufferWidth = rect.right - rect.left;
			bufferHeight = rect.bottom - rect.top;
			pixel *ps = new pixel[selectRect.width * selectRect.height];

			HGDIOBJ old = SelectObject(hdcMem, hbitmap);

			for (int i = 0; i < selectRect.height; i++){
				memcpy(&ps[i * selectRect.width], &capturePixels[(i + selectRect.y) * bufferWidth + selectRect.x], selectRect.width * 4);
			}

			SetDIBits(hdc, capture, 0, selectRect.height, ps, &dbmi, 0);

			ImageCodecInfo info = pImageCodecInfo[openFile.nFilterIndex - 1];

			wchar_t *fne = new wchar_t[wcslen(info.FilenameExtension) + 1];
			wcscpy_s(fne, wcslen(info.FilenameExtension) + 1, info.FilenameExtension);

			wchar_t *context = NULL;
			wchar_t *c = wcstok_s(fne, L";", &context);
			wchar_t *first = c;

			bool found = false;

			while (c != NULL){
				wstring str(filePath);
				transform(str.begin(), str.end(), str.begin(), toupper);
				wstring suffix(c);
				suffix = suffix.substr(1);
				if (str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0){
					found = true;
				}
				c = wcstok_s(NULL, L";", &context);
			}

			wstring path(filePath);

			if (!found){
				wstring extension = wstring(first).substr(1);
				transform(extension.begin(), extension.end(), extension.begin(), tolower);
				path = path + extension;
			}

			Bitmap bitmap(capture, NULL);
			bitmap.Save(path.c_str(), &(info.Clsid));

			delete[] fne;

			SelectObject(hdc, old);

			ReleaseDC(NULL, hdc);
			DeleteDC(hdcMem);
			DeleteObject(capture);
			delete[] ps;
			delete[] pImageCodecInfo;
		}
		break;
	}
}