bool CDocCommands::SaveImage() { CWaitCursor Wait; CImageObject* pObject = m_DocWindow.GetSelectedObject(); if (!pObject) { CMessageBox::NoObjectSelected(); return false; } CString strFilePath = StripExtension(pObject->GetSourceFile()); LPCTSTR pstrFilter = _T("All Supported Files (*.bmp, *.jpg)\0*.bmp;*.jpg\0Bitmap Files (*.bmp)\0*.bmp\0JPG Files (*.jpg)\0*.jpg\0All Files (*.*)\0*.*\0\0"); CFileDialog FileDialog(false, _T("jpg"), strFilePath, OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT, pstrFilter, m_DocWindow/*hWndParent*/); FileDialog.m_ofn.lpstrTitle = _T("Save an Image File"); if (FileDialog.DoModal(m_DocWindow) == IDCANCEL) return false; CString strFileName = FileDialog.m_ofn.lpstrFile; bool bOK = false; BITMAPINFOHEADER* pDib = pObject->GetDib(true/*bForDraw*/); // DibForDraw gives us the rotated image if (pDib) { CString strExtension = StrExtension(strFileName); if (strExtension == ".bmp") bOK = DibWrite(pDib, strFileName); else if (strExtension == ".jpg") bOK = ConvertDibToJpg(pDib, 100, strFileName); } if (!bOK) CMessageBox::Message(String("Error saving to file '%s'.", strFileName)); return bOK; }
bool CFYSPrintDoc::DumpImageFile(CAGSymImage* pSymImage, CString& strImagePath) { FileStruct* pfs = GetMRAImageFileSpec(); if (!pfs) { SetError(String("Unknown Error writing Image file")); return false; } DWORD dwSrcSize = 0; BYTE* pMemory = pSymImage->GetImage(dwSrcSize); CString strImageFile = strImagePath + pfs->FileName; if (pSymImage->GetNativeType() != "DIB") { FILE* imgout = NULL; errno_t err = fopen_s(&imgout, strImageFile, "wb"); if (!imgout || err != 0) { SetError(String("Failed to create %s", strImageFile)); return false; } fwrite(pMemory, sizeof(BYTE), dwSrcSize, imgout); fclose(imgout); } else { if (!DibWrite((BITMAPINFOHEADER*)pMemory, strImageFile)) { SetError(String("Failed to create %s", strImageFile)); return false; } } CCRC32::FileCrc32Assembly(strImageFile, pfs->dwCRC32); return true; }