⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voimage.cpp

📁 采用Platform Builder编写的多线程程序
💻 CPP
字号:
// VOIMAGE.cpp: implementation of the CVOIMAGE class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "VOIMAGE.h"



#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

HDC		CVOImage::g_hdc;
int		CVOImage::g_iScale = 100;
int		CVOImage::g_iMaxWidth = 10000;
int		CVOImage::g_iMaxHeight = 10000;
BOOL	CVOImage::g_bStretchBlt = FALSE;

CVOImage::CVOImage()
{
	m_hbitmap = 0;
}

CVOImage::~CVOImage()
{
	if(m_hbitmap)
		DeleteObject(m_hbitmap);


}

HBITMAP CVOImage::Load(HDC hdc, LPCTSTR pcszFileName)
{
	if(m_hbitmap)
		DeleteObject(m_hbitmap);

	if(!g_hdc)
		g_hdc = CreateCompatibleDC(hdc);

	HRESULT hr;
	BYTE    szBuffer[4096] = {0};
	HANDLE hFile = INVALID_HANDLE_VALUE;

	DecompressImageInfo	dii;

	hFile = CreateFile(pcszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if (hFile == INVALID_HANDLE_VALUE)
		//return FALSE;
		return;

	// Fill in the 'DecompressImageInfo' structure
	dii.dwSize = sizeof( DecompressImageInfo );		// Size of this structure
	dii.pbBuffer = szBuffer;						// Pointer to the buffer to use for data
	dii.dwBufferMax = 4096;							// Size of the buffer
	dii.dwBufferCurrent = 0;						// The amount of data which is current in the buffer
	dii.phBM = &m_hbitmap;							// Pointer to the bitmap returned (can be NULL)
	dii.ppImageRender = NULL;						// Pointer to an IImageRender object (can be NULL)
	dii.iBitDepth = GetDeviceCaps(hdc,BITSPIXEL);	// Bit depth of the output image
	dii.lParam = ( LPARAM ) hFile;					// User parameter for callback functions
	dii.hdc = g_hdc;								// HDC to use for retrieving palettes
	dii.iScale = g_iScale;							// Scale factor (1 - 100)
	dii.iMaxWidth = g_iMaxWidth;					// Maximum width of the output image
	dii.iMaxHeight = g_iMaxHeight;					// Maxumum height of the output image
	dii.pfnGetData = GetImageData;					// Callback function to get image data
	dii.pfnImageProgress = ImageProgress;			// Callback function to notify caller of progress decoding the image
	dii.crTransparentOverride = ( UINT ) -1;		// If this color is not (UINT)-1, it will override the
													// transparent color in the image with this color. (GIF ONLY)

	// Process and decompress the image data
	hr = DecompressImageIndirect( &dii );
		
	// Clean up 
	CloseHandle( hFile );

//	BITMAP	bmp;

//	GetObject(m_hbitmap, sizeof(BITMAP), &bmp);
	return m_hbitmap;
}



//BOOL CVOImage::Draw(HDC hdc, int x, int y, int cx, int cy)
BOOL CVOImage::Draw(HDC hdc, long x1, long y1, long xWidth, long yHeight,long x2,long y2)
{
	BITMAP	bmp;
	HGDIOBJ	hOldBitmap;


	hOldBitmap = SelectObject(g_hdc, m_hbitmap);
	GetObject(m_hbitmap, sizeof(BITMAP), &bmp);

	BitBlt(hdc, x1, y1, xWidth, yHeight, g_hdc,x2,y2,SRCCOPY );

    
	SelectObject(g_hdc, hOldBitmap);



	return TRUE;
}





DWORD CALLBACK CVOImage::GetImageData(LPSTR szBuffer, DWORD dwBufferMax, LPARAM lParam )
{
	DWORD dwNumberOfBytesRead;

	if ( (HANDLE)lParam == INVALID_HANDLE_VALUE )
		return 0;

	ReadFile( (HANDLE)lParam, szBuffer, dwBufferMax, &dwNumberOfBytesRead, NULL );

	// Return number of bytes read
	return dwNumberOfBytesRead;
}



void CALLBACK CVOImage::ImageProgress(IImageRender *pRender, BOOL bComplete, LPARAM lParam )
{
	if( bComplete )
	{
		;// (Optional) add code here for completion processing
	}
}

BOOL CVOImage::IsLoaded()
{
	return (m_hbitmap != 0);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -