用ImageStone显示透明PNG图片
背景我在开发一款商业软件(518抽奖软件:http://www.)的时候,使用了开源的ImageStone图像处理库,并将图片显示的代码封装为一个C++类,可显示透明PNG图片。
H文件
#ifndef _Timg_h_
#define _Timg_h_
class Timg
{
public:
Timg ();
~Timg ();
void* img;
BOOL load (const WCHAR* file);
void unload ();
BOOL isLoad ();
void draw (HDC hDc, RECT rc);
int getWidth ();
int getHeight ();
void stretch (int maxSize);
BOOL save (const WCHAR* file);
};
#endif
CPP文件
#include
#include "_Timg.h"
#include "ImageStone.h"
Timg::Timg ()
{
img = new FCObjImage();
}
Timg::~Timg ()
{
delete (FCObjImage*)img;
}
BOOL Timg::load (const WCHAR* file)
{
if ( ((FCObjImage*)img)->Load(file, NULL) ) {
if (((FCObjImage*)img)->ColorBits() == 32)
((FCObjImage*)img)->ApplyEffect (FCEffectPremultipleAlpha());//透明预处理
return TRUE;
}
return FALSE;
}
BOOL Timg::isLoad ()
{
return ((FCObjImage*)img)->IsValidImage ();
}
void Timg::unload ()
{
((FCObjImage*)img)->Destroy ();
}
void Timg::draw (HDC hDc, RECT rc)
{
((FCObjImage*)img)->Draw (hDc, rc);
}
int Timg::getWidth ()
{
return ((FCObjImage*)img)->Width ();
}
int Timg::getHeight ()
{
return ((FCObjImage*)img)->Height ();
}
void Timg::stretch (int maxSize)
{
int w = ((FCObjImage*)img)->Width();
int h = ((FCObjImage*)img)->Height();
if (w<=0 || h<=0) return;
double r;
if (w >= h) r = (double)maxSize / (double)w;
else r = (double)maxSize / (double)h;
((FCObjImage*)img)->Stretch (w*r, h*r);
}
BOOL Timg::save (const WCHAR* file)
{
return ((FCObjImage*)img)->Save(file);
}
518抽奖软件下载:http://www.
ImageStone下载:http://www.