資源簡(jiǎn)介
Bitmap b(image.GetWidth(),image.GetHeight());如何使用GDI+制作圓形圖片(類似QQ圓形頭像)(MFC,VC)

代碼片段和文件信息
//?RoundStatic.cpp?:?實(shí)現(xiàn)文件
//
#include?“stdafx.h“
#include?“TestYuan.h“
#include?“RoundStatic.h“
#include?“.\roundstatic.h“
//?CRoundStatic
IMPLEMENT_DYNAMIC(CRoundStatic?CStatic)
CRoundStatic::CRoundStatic()
{
m_b=0;
}
CRoundStatic::~CRoundStatic()
{
}
BEGIN_MESSAGE_MAP(CRoundStatic?CStatic)
ON_WM_ERASEBKGND()
ON_WM_DESTROY()
ON_WM_PAINT()
END_MESSAGE_MAP()
//?CRoundStatic?消息處理程序
BOOL?CRoundStatic::OnEraseBkgnd(CDC*?pDC)
{
if(m_b)
{
CRect?rect;
GetWindowRect(&rect);//<-----******
Graphics?go(pDC->m_hDC);
//go.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);?
//go.SetInterpolationMode(Gdiplus::InterpolationModeHighQuality);?
go.DrawImage(m_b?00?rect.Width()?rect.Height());
return?0;
}
return?CStatic::OnEraseBkgnd(pDC);
}
bool?CRoundStatic::LoadFile(CString?szDile)
{
if(m_b)
{
::delete?m_b;
m_b=0;
}
CString?file=szDile;
//方法一
//Image?image(file);
//m_b=::new?Bitmap(image.GetWidth()image.GetHeight());
//Graphics?g(m_b);
//g.FillEllipse(&TextureBrush(&image)?0?0?image.GetWidth()?image.GetHeight());
//方法二
Image?image(file);
m_b=::new?Bitmap(image.GetWidth()image.GetHeight());
Graphics?g(m_b);
g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);?
GraphicsPath?p(FillModeAlternate);
p.AddEllipse(0?0?image.GetWidth()?image.GetHeight());
g.FillPath(&TextureBrush(&image)?&p);
this->Invalidate();
return?true;
////獲取編碼器的CLSID?[class?id]??
//UINT?num=0;?????????????????????//圖像編碼器的數(shù)量??
//UINT?size=0;????????????????????//圖像編碼器數(shù)組的字節(jié)數(shù)??
//CLSID?encoderClsid;??
//ImageCodecInfo*?pICI=NULL;??
//??
//GetImageEncodersSize(&num&size);//獲得系統(tǒng)編碼器的數(shù)量和大小??
//if(size==0)?return?false;//失敗??
//??
//pICI?=?(ImageCodecInfo*)(malloc(size));?//編碼器??
//if(pICI==NULL)?return?false;//失敗??
//??
//GetImageEncoders(numsizepICI);????//獲取編碼器信息??
//for(int?j=0;j //{??
// if(wcscmp(pICI[j].MimeTypeL“image/png“)==0)//jpeg?bmp?gif?tiff?png??
// {??
// encoderClsid?=?pICI[j].Clsid;??
// }??
//}??
//free(pICI);??
}
bool?CRoundStatic::SaveFile(CString?szDile)
{
CString?file=szDile;
//方法一
//Image?image(file);
//m_b=::new?Bitmap(image.GetWidth()image.GetHeight());
//Graphics?g(b);
//g.FillEllipse(&TextureBrush(&image)?0?0?image.GetWidth()?image.GetHeight());
//方法二
Image?image(file);
Bitmap?b(image.GetWidth()image.GetHeight());
Graphics?g(&b);
g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);?
GraphicsPath?p(FillModeAlternate);
p.AddEllipse(0?0?image.GetWidth()?image.GetHeight());
g.FillPath(&TextureBrush(&image)?&p);
//獲取編碼器的CLSID?[class?id]??
UINT?num=0;?????????????????????//圖像編碼器的數(shù)量??
UINT?size=0;????????????????????//圖像編碼器數(shù)組的字節(jié)數(shù)??
CLSID?encoderClsid;??
ImageCodecInfo*?pICI=NULL;??
??
GetImageEncodersSize(&num&size);//獲得系統(tǒng)編碼器的數(shù)量和大小??
if(size==0)?return?false;//失敗??
??
pICI?=?(ImageCodecInfo*)(malloc(size
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
????.CA....?????94413??2017-04-10?20:10??TestYuan\173318129.jpg
????.CA....?????94413??2017-04-10?20:10??TestYuan\Debug\173318129.jpg
????.CA....????739088??2017-07-29?15:00??TestYuan\Debug\173318129.png
????.CA....???2338816??2017-07-29?15:02??TestYuan\Debug\TestYuan.exe
????.CA....??????2834??2017-07-28?09:54??TestYuan\ReadMe.txt
????.CA....???1805054??2017-07-28?10:08??TestYuan\res\bitmap1.bmp
????.CA....?????21630??2003-04-02?03:36??TestYuan\res\TestYuan.ico
????.CA....???????697??2017-07-28?09:54??TestYuan\res\TestYuan.manifest
????.CA....???????364??2017-07-28?09:54??TestYuan\res\TestYuan.rc2
????.CA....???????909??2017-07-28?17:12??TestYuan\resource.h
????.CA....??????3812??2017-07-29?14:54??TestYuan\RoundStatic.cpp
????.CA....???????587??2017-07-29?14:55??TestYuan\RoundStatic.h
????.CA....???????137??2017-07-28?09:54??TestYuan\stdafx.cpp
????.CA....??????1754??2017-07-28?16:16??TestYuan\stdafx.h
????.CA....???1863868??2017-07-29?15:02??TestYuan\TestYuan.aps
????.CA....??????1811??2017-07-28?10:21??TestYuan\TestYuan.cpp
????.CA....???????479??2017-07-28?10:20??TestYuan\TestYuan.h
????.CA....?????35840??2017-07-29?15:05??TestYuan\TestYuan.ncb
????.CA....??????5573??2017-07-29?15:02??TestYuan\TestYuan.rc
????.CA....???????905??2017-07-29?14:48??TestYuan\TestYuan.sln
????.CA..H.??????8704??2017-07-29?15:05??TestYuan\TestYuan.suo
????.CA....??????4949??2017-07-29?14:59??TestYuan\TestYuan.vcproj
????.CA....??????8730??2017-07-29?14:55??TestYuan\TestYuanDlg.cpp
????.CA....???????816??2017-07-28?17:12??TestYuan\TestYuanDlg.h
????.CA....????730158??2017-07-28?15:05??TestYuan\tranparentPic.png
????.C.D...?????????0??2017-07-29?15:05??TestYuan\Debug
????.C.D...?????????0??2017-07-29?15:00??TestYuan\res
????.C.D...?????????0??2017-07-29?15:02??TestYuan
-----------?---------??----------?-----??----
??????????????7766341????????????????????28
............此處省略1個(gè)文件信息
評(píng)論
共有 條評(píng)論