Example #1
0
// 指定されたフォーマットに対応する Encoder の CLSID を取得する
// Cited from MSDN Library: Retrieving the Class Identifier for an Encoder
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

   ImageCodecInfo* pImageCodecInfo = NULL;

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

   pImageCodecInfo = (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;  
}
Example #3
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 #4
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;
}
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 #6
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 #7
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 #8
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;
	}
}