示例#1
0
	bool CImage::SaveFile(const std::wstring& strFileName, UINT nFileType)
	{
		CBgraFrame oBgraFrame;
		oBgraFrame.put_Width(m_dwWidth);
		oBgraFrame.put_Height(m_dwHeight);
		oBgraFrame.put_Stride(m_nStride);
		oBgraFrame.put_Data(m_pImgData);
		bool bRes = oBgraFrame.SaveFile(strFileName, nFileType);
		//чтобы не удалялся на destructor
		oBgraFrame.put_Data(NULL);
		return bRes;
	}
示例#2
0
    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;
	}
示例#3
0
	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();
	}
示例#4
0
文件: Image.cpp 项目: ONLYOFFICE/core
    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();
    }
	inline Global::_BlipType SaveImageToFileFromDIB(unsigned char* data, int size, const std::wstring& file_name)//without ext
	{
		Global::_BlipType result = Global::msoblipERROR;

		CBgraFrame oFrame;
		int offset = 0, biSizeImage = 0;

		__BITMAPINFOHEADER * header = (__BITMAPINFOHEADER*)data;
		if (!header) return result;

		result = Global::msoblipDIB;

		if (header->biWidth > 100000 || header->biHeight > 100000 || header->biSize != 40)
		{
			__BITMAPCOREHEADER * header_core = (__BITMAPCOREHEADER *)data;
			if (header_core->bcSize != 12)
			{
				result = Global::msoblipWMF;
			}
			else
			{
				offset = 12; //sizeof(BITMAPCOREHEADER)			
			
				oFrame.put_Height	(header_core->bcHeight );
				oFrame.put_Width	(header_core->bcWidth );
				
				int sz_bitmap = header_core->bcHeight * header_core->bcWidth * header_core->bcBitCount/ 8;
				
				//if (header_core->bcWidth % 2 != 0 && sz_bitmap < size - offset)
				//	header_core->bcWidth++;
				///???? todooo непонятно .. в biff5 нужно флипать картинку, в biff8 не ясно ( - 
				
				int stride =  -(size - offset) / header_core->bcHeight;
				oFrame.put_Stride	(stride/*header_core->bcBitCount * header_core->bcWidth /8 */);

				biSizeImage = size - offset;
				
				if (-stride >= header_core->bcWidth && header_core->bcBitCount >=24 )
				{
					result = Global::msoblipPNG;
				}
			}
		}
		else
		{
			offset = 40; //sizeof(BITMAPINFOHEADER)

			oFrame.put_Height	(header->biHeight );
			oFrame.put_Width	(header->biWidth );
			
			int sz_bitmap = header->biHeight * header->biWidth * header->biBitCount/ 8;
			
			//if (header->biWidth % 2 != 0 && sz_bitmap < size -offset)
			//	header->biWidth++;
			
			int stride = -(size - offset) / header->biHeight;

			if (-stride >= header->biWidth && header->biBitCount >= 24)
			{
				result = Global::msoblipPNG;
			}
			oFrame.put_Stride	(stride/*header->biBitCount * header->biWidth /8*/);
			
			biSizeImage = header->biSizeImage > 0 ? header->biSizeImage : (size - offset);
		}
		
//------------------------------------------------------------------------------------------

		if (result == Global::msoblipPNG)
		{
			oFrame.put_Data((unsigned char*)data + offset);
			
            if (!oFrame.SaveFile(file_name + L".png", 4/*CXIMAGE_FORMAT_PNG*/))
				result = Global::msoblipERROR;

			oFrame.put_Data(NULL);
		}
		else if (result == Global::msoblipWMF)
		{
			NSFile::CFileBinary file;
            if (file.CreateFileW(file_name + L".wmf"))
			{
				file.WriteFile((BYTE*)data, size);
				file.CloseFile();
			}
		}
		else if (biSizeImage > 0)
		{
			NSFile::CFileBinary file;
            if (file.CreateFileW(file_name + L".bmp"))
			{
                _UINT16 vtType		= 0x4D42;				file.WriteFile((BYTE*)&vtType,	2);
                _UINT32 dwLen		= biSizeImage;			file.WriteFile((BYTE*)&dwLen,	4);
                _UINT32 dwRes		= 0;					file.WriteFile((BYTE*)&dwRes,	4);
                _UINT32 dwOffset	= 2;					file.WriteFile((BYTE*)&dwOffset, 4);
			
				file.WriteFile((BYTE*)data, size);
				file.CloseFile();
			}
		}
		return result;
	}