void CImage::Create(const std::wstring& filename) { Destroy(); CBgraFrame oFrame; bool bOpen = oFrame.OpenFile(filename); if (bOpen) { m_pImgData = oFrame.get_Data(); m_dwWidth = (DWORD)oFrame.get_Width(); m_dwHeight = (DWORD)oFrame.get_Height(); m_nStride = oFrame.get_Stride(); m_Status = Ok; } oFrame.ClearNoAttack(); }
static void CorrectImage(const wchar_t* wsFileName, BYTE*& pBuffer, int& nBufferSize, unsigned int& unWidth, unsigned int& unHeight) { pBuffer = NULL; nBufferSize = 0; CImageFileFormatChecker oChecker(wsFileName); if (oChecker.eFileType != _CXIMAGE_FORMAT_JPG) return; NSFile::CFileBinary oFile; if (!oFile.OpenFile(wsFileName)) return; if (20 > oFile.GetFileSize()) return; BYTE data[20]; DWORD dwRead = 0; if (!oFile.ReadFile(data, 20, dwRead)) return; std::string sFind((char*)data, 20); oFile.CloseFile(); if (std::string::npos == sFind.find("Photoshop") && std::string::npos == sFind.find("photoshop")) return; CBgraFrame oFrame; if (!oFrame.OpenFile(wsFileName)) return; oFrame.SetJpegQuality(85.0); if (!oFrame.Encode(pBuffer, nBufferSize, _CXIMAGE_FORMAT_JPG)) return; if (!pBuffer || !nBufferSize) return; unWidth = (unsigned int)oFrame.get_Width(); unHeight = (unsigned int)oFrame.get_Height(); }
bool GetResolution(const wchar_t* fileName, int & Width, int &Height, CApplicationFonts * appFonts) { CBgraFrame image; MetaFile::CMetaFile meta_file(appFonts); if ( meta_file.LoadFromFile(fileName)) { double dX = 0, dY = 0, dW = 0, dH = 0; meta_file.GetBounds(&dX, &dY, &dW, &dH); Width = dW; Height = dH; } else if ( image.OpenFile(fileName, 0 )) { Width = image.get_Width(); Height = image.get_Height(); return true; } return false; }