//-------------------------------------------------------------------
// VOImage implementation
//-------------------------------------------------------------------
//
// Copyright �2000 Virtual Office Systems Incorporated
// All Rights Reserved
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included.
//
// This code can be compiled, modified and distributed freely, providing
// that this copyright information remains intact in the distribution.
//
// This code may be compiled in original or modified form in any private
// or commercial application.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage, in any form, caused
// by this code. Use it at your own risk.
//-------------------------------------------------------------------
#include "stdafx.h"
#include "VOImage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#ifdef _WIN32_WCE
#pragma comment(lib, "imgdecmp.lib")
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int CVOImage::g_iScale = 100;
int CVOImage::g_iMaxWidth = 10000;
int CVOImage::g_iMaxHeight = 10000;
BOOL CVOImage::g_bStretchBlt = FALSE;
CVOImage::CVOImage() : m_hdc(0), m_hbitmap(0), m_dwWidth(0), m_dwHeight(0), m_hmoduleResource(0), m_dwResourceID(0)
{
}
CVOImage::~CVOImage()
{
if(m_hdc)
DeleteDC(m_hdc);
if(m_hbitmap)
DeleteObject(m_hbitmap);
}
BOOL CVOImage::Load(HDC hdc, LPCTSTR pcszFileName)
{
if(m_hbitmap)
{
if(GetFileName().GetLength() && GetFileName() == pcszFileName)
return TRUE; // Already Loaded
DeleteObject(m_hbitmap);
}
if(!m_hdc)
{
m_hdc = CreateCompatibleDC(hdc);
HBITMAP hbitmap = CreateCompatibleBitmap(hdc, GetDeviceCaps(hdc, HORZRES), GetDeviceCaps(hdc, VERTRES));
SelectObject(m_hdc, hbitmap);
}
BYTE szBuffer[1024] = {0};
HANDLE hFile = INVALID_HANDLE_VALUE;
#ifdef _WIN32_WCE
HRESULT hr;
DecompressImageInfo dii;
#endif
hFile = CreateFile(pcszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
#ifdef _WIN32_WCE
// 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 = 1024; // 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 = m_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 );
#endif
// Clean up
CloseHandle( hFile );
HBITMAP hbitmapOld = (HBITMAP)SelectObject(m_hdc, m_hbitmap);
DeleteObject(hbitmapOld);
BITMAP bmp;
GetObject(m_hbitmap, sizeof(BITMAP), &bmp);
m_dwWidth = bmp.bmWidth;
m_dwHeight = bmp.bmHeight;
m_strFileName = pcszFileName;
m_dwResourceID = 0;
m_hmoduleResource = 0;
return TRUE;
}
HBITMAP CVOImage::Copy(int cx, int cy, int nCanvasWidth, int nCanvasHeight)
{
BITMAP bm, bmNew;
HBITMAP hNew;
BOOL fStretch = (cx == -1) || (cy == -1);
::GetObject(m_hbitmap, sizeof(BITMAP), &bm);
HDC hdc = CreateCompatibleDC(m_hdc);
if(cx == -1)
{
if(cy == -1)
{ // Both are default.
cx = bm.bmWidth;
cy = bm.bmHeight;
fStretch = FALSE;
}
else
{ // Get cx from cy value
float fltAspect = (float)bm.bmWidth / (float)bm.bmHeight;
cx = (int) ((float)cy * fltAspect);
}
}
else if(cy == -1)
{ // Get cy from cx value
float fltAspect = (float)bm.bmHeight / (float)bm.bmWidth;
cy = (int) ((float)cx * fltAspect);
}
if((nCanvasWidth == -1) || (nCanvasHeight == -1))
{
if(cx < cy)
{
nCanvasWidth = cy;
nCanvasHeight = cy;
}
else
{
nCanvasWidth = cx;
nCanvasHeight = cx;
}
}
// hNew = CreateCompatibleBitmap(m_hdc, cx, cy);
hNew = CreateCompatibleBitmap(m_hdc, nCanvasWidth, nCanvasHeight);
SelectObject(hdc, hNew);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = nCanvasWidth;
rect.bottom = nCanvasHeight;
// HBRUSH hbrushBG = CreateSolidBrush(GetPixel(0, 0));
FillRect(hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
// FillRect(hdc, &rect, hbrushBG);
// DeleteObject(hbrushBG);
if(DrawTransparent(hdc, 0, 0, cx, cy, GetPixel(0, 0)) )
{
HBITMAP hPrev = (HBITMAP) ::GetObject(hNew, sizeof(BITMAP), &bmNew);
::SelectObject(hdc, hPrev);
}
DeleteDC(hdc);
return hNew;
}
BOOL CVOImage::Draw(HDC hdc, int x, int y, int cx, int cy)
{
BITMAP bmp;
g_bStretchBlt = !(cx == -1 && cy == -1);
GetObject(m_hbitmap, sizeof(BITMAP), &bmp);
if (g_bStretchBlt) // Stretch to fit
StretchBlt(hdc, x , y, cx, cy, m_hdc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY );
else
BitBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, m_hdc,0,0,SRCCOPY );
return TRUE;
}
BOOL CVOImage::DrawTranslucent(HDC hdc, int x, int y, int nPercent, int cx, int cy, COLORREF TransparentColor)
{
BITMAP bmpBG, bmpImage;
HDC hdcBG = CreateCompatibleDC(hdc);
HDC hdcImage = CreateCompatibleDC(hdc);
if(cx == -1)
cx = GetWidth();
if(cy == -1)
cy = GetHeight();
BITMAPINFO i;
memset( &i.bmiHeader, 0, sizeof(BITMAPINFOHEADER) );
i.bmiHeader.biWidth=cx;
i.bmiHeader.biHeight=cy;
i.bmiHeader.biPlanes=1;
i.bmiHeader.biBitCount=24;
i.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
PBYTE pBitsBG;
HBITMAP hbitmapBG = CreateDIBSection(hdc, &i, DIB_RGB_COLORS, (PVOID*)&pBitsBG, NULL, 0 );
if(hbitmapBG == 0)
{
DWORD dwError = GetLastError();
DebugBreak();
return FALSE;
}
// Copy the background into the 24bit Background DIB
HBITMAP hbitmapOld = (HBITMAP)SelectObject(hdcBG, hbitmapBG);
BitBlt(hdcBG, 0, 0, cx, cy, hdc, x, y, SRCCOPY);
SelectObject(hdcBG, hbitmapOld);
// Create a matching 24bit DIB Section to hold the image data
PBYTE pBitsImage;
HBITMAP hbitmapImage = CreateDIBSection(hdc, &i, DIB_RGB_COLORS, (PVOID*)&pBitsImage, NULL, 0 );
if(hbitmapImage == 0)
{
DWORD dwError = GetLastError();
DebugBreak();
return FALSE;
}
// Copy the bitmap into the 24bit DIB
hbitmapOld = (HBITMAP)SelectObject(hdcImage, hbitmapImage);
if(TransparentColor == RGB(192, 192, 192))
StretchBlt(hdcImage, 0, 0, cx, cy, m_hdc, 0, 0, GetWidth(), GetHeight(), SRCCOPY);
else
{
#ifdef _WIN32_WCE
BitBlt(hdcImage, 0, 0, cx, cy, hdc, x, y, SRCCOPY);
TransparentImage(hdcImage, 0, 0, cx, cy, m_hdc, 0, 0, GetWidth(), GetHeight(), TransparentColor);
#else
StretchBlt(hdcImage, 0, 0, cx, cy, m_hdc, 0, 0,
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
voimage.zip (4个子文件)
voimage.cpp 15KB
VOIMAGE.H 3KB
INCLUDE.ZIP 3KB
imgdecmp.dll 96KB
共 4 条
- 1
资源评论
- MAJIA19182012-10-31少了个LIB文件,不过还是谢谢楼主
- lsrcoolboy2013-07-12不知道怎么回事老报错,可能是我自己的问题
omewk
- 粉丝: 3
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功