c# - Outer Glow Effect for Text in a Custom Control -


how apply outer glow on text of label in c# winforms, , blur effect. using custom control

as see, custom panel , i'm trying glow effect entire text.

protected override void onpaint(painteventargs pe) {     //base.onpaint(pe);     stringformat sf = new stringformat();     sf.alignment = stringalignment.center;     sf.linealignment = stringalignment.center;      graphicspath gp = new graphicspath();     gp.fillmode = fillmode.alternate;      gp.addstring(this.text, this.font.fontfamily, 2, 12f, new point(clientrectangle.x+text.length*4-20, clientrectangle.y+10), sf);      // in border     using (solidbrush brush = new solidbrush(backcolor))         pe.graphics.fillrectangle(brush, clientrectangle);     pe.graphics.drawrectangle(new pen(color.fromargb(_innerbordercolor.r, _innerbordercolor.b, _innerbordercolor.g), 1.0f), 0, 0, clientsize.width - 2, clientsize.height - 2);       pe.graphics.drawpath(new pen(color.blue, 2f), gp);     pe.graphics.drawstring(base.text, this.font, brushes.black, 2, 2);  } 

drawing text halo or aura

by bob powell (unfortunately site down)

the technique relies on drawing text twice. once shrunken bitmap represents halo, expanded full size using interpolation mode of choice, , once @ full size create actual text. bitmap used create halo must of specific size ratio original text. in case have chosen ratio of 1:5 halo text must drawn @ 1 fifth size.

here's how works:

  1. create new bitmap smaller original drawing area fixed ratio. in case 1/5th.
  2. create graphicspath , had desired text it.
  3. obtain graphics object bitmap , create matrix shrinks drawing output chosen ratio.
  4. fill text path using desired halo color , then, measure, stroke text path pen provide little bit of edge aura.
  5. set interpolation mode in destination graphics object highqualitybilinear , stretch bitmap containing halo using chosen ratio again.
  6. finally, on destination graphics object, fill text path without changing size. should register text correctly fuzzy outline of halo , produce final effect.

code:

private void form1_paint(object sender, system.windows.forms.painteventargs e) {   //create bitmap in fixed ratio original drawing area.   bitmap bm=new bitmap(this.clientsize.width/5, this.clientsize.height/5);   //create graphicspath object.    graphicspath pth=new graphicspath();   //add string in chosen style.    pth.addstring("text halo",new fontfamily("verdana"),(int)fontstyle.regular,100,new point(20,20),stringformat.generictypographic);   //get graphics object image.    graphics g=graphics.fromimage(bm);   //create matrix shrinks drawing output fixed ratio.    matrix mx=new matrix(1.0f/5,0,0,1.0f/5,-(1.0f/5),-(1.0f/5));   //choose appropriate smoothing mode halo.    g.smoothingmode=smoothingmode.antialias;   //transform graphics object same half may used both halo , text output.    g.transform=mx;   //using suitable pen...   pen p=new pen(color.yellow,3);   //draw around outline of path   g.drawpath(p,pth);   //and fill in measure.    g.fillpath(brushes.yellow,pth);   //we no longer need graphics object   g.dispose();   //this shifts effect little bit edge isn't cut off in demonstration   e.graphics.transform=new matrix(1,0,0,1,50,50);   //setup smoothing mode path drawing   e.graphics.smoothingmode=smoothingmode.antialias;   //and interpolation mode expansion of halo bitmap   e.graphics.interpolationmode=interpolationmode.highqualitybicubic;   //expand halo making edges nice , fuzzy.    e.graphics.drawimage(bm,clientrectangle,0,0,bm.width,bm.height,graphicsunit.pixel);   //redraw original text   e.graphics.fillpath(brushes.black,pth);   //and you're done.    pth.dispose(); } 

screenshot:

enter image description here


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -