c++GDI+发光子与发光边框画法

Yun__ 2013-01-14 04:08:58
加精

这个是结果
下面是画法
自己包含头文件

问题是。。 我应该怎么即时释放掉GDI+的资源?
#pragma once
#include "stdafx.h"
using namespace Gdiplus;
WCHAR* ToWChar(char * str)

{
static WCHAR buffer[1024];

_wcsset_s(buffer,0);

MultiByteToWideChar(CP_ACP,0,str,strlen(str),buffer,1024);

return buffer;

}
void DrawFont(HDC mDc,int vague , RECT rect,char * text,char *fontname,int fontsize,Color color,Color shadowcolor,int offset)
{
if (mDc !=NULL && text !=NULL &&fontsize >0)
{
Graphics *g=Graphics ::FromHDC (mDc );

g->SetCompositingQuality (CompositingQualityAssumeLinear);
g->SetSmoothingMode(SmoothingModeAntiAlias);
g->SetTextRenderingHint(TextRenderingHintAntiAlias);
Bitmap bit1(rect .right ,rect .bottom,PixelFormat32bppARGB );
Graphics *g1 =Graphics ::FromImage (&bit1);
g1->SetCompositingQuality (CompositingQualityAssumeLinear);
g1->SetSmoothingMode(SmoothingModeAntiAlias);
g1->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit );
Bitmap bit2(rect .right / vague+strlen (text)/10,rect .bottom / vague ,PixelFormat32bppARGB );
Graphics *g2 =Graphics ::FromImage (&bit2);
g2->SetInterpolationMode(InterpolationModeHighQualityBicubic );
g2->SetPixelOffsetMode(PixelOffsetModeNone );

SolidBrush brush(shadowcolor);
FontFamily fontFamily(ToWChar(fontname ) );
Gdiplus::Font Font(&fontFamily, fontsize ,FontStyleRegular , UnitPoint);//
PointF p(3 ,3 );

g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );
g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );


g2->DrawImage (&bit1,0,0,rect .right / vague +strlen (text)/10,rect .bottom / vague );
g1->Clear (0);
g1->DrawImage (&bit2 ,offset,0,rect .right ,rect .bottom);
g1->SetTextRenderingHint (TextRenderingHintAntiAlias);

brush .SetColor (color);
g1->DrawString (ToWChar (text ),strlen (text),&Font,p ,&brush );
g->DrawImage (&bit1 ,rect .left ,rect.top );

}
}
void DrawFrame(HDC mDc,Size st,int Fillet,Color ShineColor,Color InteriorColor,int offset,Size zoom)
{
int Size_w,Size_h;
Size_w =st.Width ;
Size_h =st.Height ;
Graphics g(mDc );
g.SetPixelOffsetMode(PixelOffsetModeHalf );
g.SetSmoothingMode (SmoothingModeAntiAlias );
g.SetCompositingQuality (CompositingQualityHighQuality );
GraphicsPath path;
int r = Fillet ;
int l = 2 * r;
path.AddArc (offset , offset, l, l, 180, 90);
path.AddArc (Size_w - offset - l - zoom.Width , offset, l, l, 270, 90);
path.AddArc (Size_w - offset - l - zoom.Width , Size_h - offset - l - zoom.Height , l, l, 0, 90);
path.AddArc (offset, Size_h - offset - l - zoom.Height , l, l, 90, 90);
path.CloseAllFigures ();
int R=ShineColor .GetR (),G=ShineColor .GetG (),B=ShineColor .GetB ();

Pen p(Color (10,R ,G,B),11);
p.SetWidth (11);
p.SetColor (Color (10,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (9);
p.SetColor (Color (20,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (7);
p.SetColor (Color (40,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (5);
p.SetColor (Color (55,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (3);
p.SetColor (Color (70,R ,G,B));
g.DrawPath (&p,&path);
p.SetWidth (1);
R= InteriorColor .GetR (),G=InteriorColor .GetG (),B=InteriorColor .GetB ();
p.SetColor (Color (255,R ,G,B));
g.DrawPath (&p,&path);
SolidBrush b(Color (2, 0, 0, 0));
HBRUSH br= CreateSolidBrush (0);
FillRgn (mDc , CreateRoundRectRgn (offset, offset,Size_w - offset + 1, Size_h - offset + 1 - zoom.Height , r + r / 3 * 2, r + r / 3 * 2),br );
g.FillRectangle(&b, offset + 1, offset + 2, Size_w - 1 - offset * 2 - 10 + Fillet, Size_h - 3 - offset * 2 - 10 +Fillet - zoom.Height );//底层图层,防止鼠标穿透
DeleteObject (br);
}
...全文
10025 72 打赏 收藏 转发到动态 举报
写回复
用AI写文章
72 条回复
切换为时间正序
请发表友善的回复…
发表回复
JYSML 2013-08-11
  • 打赏
  • 举报
回复
DrawFrame()函数在哪里调用,我在OnPaint()中调用,每重画一次,非重画区透明度降低,最总是全不透明
苒止 2013-07-01
  • 打赏
  • 举报
回复
这个字体效果不错啊
Fields_Of_Gold 2013-06-13
  • 打赏
  • 举报
回复
哈哈 好贴 最近就在研究这个
向立天 2013-06-03
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
_静以修身 2013-06-03
  • 打赏
  • 举报
回复

void Luminous(Graphics &g, int Fuzzy, Rect rectPaint, LPCWSTR Text, Rect Textrect, Font &TextFont, int FontColor, int ShadowColor) 
{     
     Bitmap Bit1(rectPaint.Width, rectPaint.Height);     
     Graphics g1(&Bit1);     
     g1.SetSmoothingMode(SmoothingModeAntiAlias);
     g1.SetTextRenderingHint(TextRenderingHintAntiAlias);     
     g1.SetCompositingQuality(CompositingQualityAssumeLinear);
     Bitmap Bit2(rectPaint.Width / Fuzzy, rectPaint.Height/ Fuzzy);     
     Graphics g2(&Bit2);
     g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);
     g2.SetPixelOffsetMode(PixelOffsetModeNone);     //布局 
     int cb = ShadowColor / 65536;
     int cg = (ShadowColor - cb * 65536) / 256;
     int cr = ShadowColor - (cb * 65536) - (cg * 256);
     SolidBrush B(Color(255, cr, cg, cb));
     GraphicsPath path;
     FontFamily ftFamily;
     TextFont.GetFamily(&ftFamily);
     path.AddString(Text,-1,&ftFamily , (int)(FontStyleBold), TextFont.GetSize(), Textrect,NULL);
     g1.FillPath(&B, &path);     //绘制文字
     g2.DrawImage(&Bit1, 0, 0, rectPaint.Width/ Fuzzy, rectPaint.Height / Fuzzy);
     g1.Clear(Color(0));
     g1.DrawImage(&Bit2, 0, 0, rectPaint.Width, rectPaint.Height);
     g1.SetTextRenderingHint(TextRenderingHintAntiAlias);     //发光字底图
     GraphicsPath path1;
     path1.AddString(Text,-1,&ftFamily, (int)(FontStyleBold),TextFont.GetSize(), Textrect,NULL/* new StringFormat()*/);
     cb = FontColor / 65536;
     cg = (FontColor - cb * 65536) / 256;
     cr = FontColor - (cb * 65536) - (cg * 256);
     B.SetColor(Color(255, cr, cg, cb));
     g1.FillPath(&B, &path1);     //绘制文字
     g.DrawImage(&Bit1, rectPaint.X, rectPaint.Y);
} 
整理下8l的代码 乱的总不愿意看
shuang_yi 2013-03-30
  • 打赏
  • 举报
回复
学习了,感谢分享
Daisy__Ben 2013-03-29
  • 打赏
  • 举报
回复
引用 65 楼 Daisy__Ben 的回复:
LZ天才啊,居然运用graphic的叠加模式做这样的效果。给大伙解释下g2->SetInterpolationMode(InterpolationModeHighQualityBicubic);的作用吧
错了,是g1->SetCompositingQuality (CompositingQualityAssumeLinear);这句?
Daisy__Ben 2013-03-29
  • 打赏
  • 举报
回复
LZ天才啊,居然运用graphic的叠加模式做这样的效果。给大伙解释下g2->SetInterpolationMode(InterpolationModeHighQualityBicubic);的作用吧
jimette 2013-03-29
  • 打赏
  • 举报
回复
VOID Example_FromHDC(HDC hdc) { Graphics* pGraphics = Graphics::FromHDC(hdc); Pen pen(Color(255, 255, 0, 0)); pGraphics->DrawRectangle(&pen, 10, 10, 200, 100); delete pGraphics; }
Gavin_1989 2013-01-31
  • 打赏
  • 举报
回复
LZV5,代码有注释可读性会更高,特别是对于我这种菜鸟来说
happyjw 2013-01-30
  • 打赏
  • 举报
回复
ww549825679 2013-01-29
  • 打赏
  • 举报
回复
 不错哇
帅哥加美女 2013-01-28
  • 打赏
  • 举报
回复
很好赞一个!!!
pupingpp 2013-01-28
  • 打赏
  • 举报
回复
mark一下
lsyplan 2013-01-28
  • 打赏
  • 举报
回复
学习了,gdi+
wjx294801971 2013-01-27
  • 打赏
  • 举报
回复
大哥,能不能给个源代码文件
Li_Carey 2013-01-26
  • 打赏
  • 举报
回复
楼主高手...
yanguichao2012 2013-01-26
  • 打赏
  • 举报
回复
引用 36 楼 zheng_xiaoxu 的回复:
每天回帖即可获得10分可用分!小技巧:教您如何更快获得可用分 你还可以输入10000个字符
积分有啥用?
ghostalker 2013-01-25
  • 打赏
  • 举报
回复
用GDI+也能写出这东西 厉害
Yun__ 2013-01-23
  • 打赏
  • 举报
回复
加载更多回复(42)

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧