.net - C# how to change bitmap image color and apply anti-aliasing -


i working on flowchart making application , involves changing color of images transparency(png). i've been searching hours workarounds , it's either it's not i'm looking or can't make work.

first, let me show codes , how it. removed parts of code unrelated question.

this class "create" flowchart symbols. inherited label class because need text centered on symbols. use images in .png format located inside resources folder , change color according user wants.

namespace pf2 {     public class terminal : label     {              public void createterminal(int x)             {                 this.width = 250;                 this.height = 100;                 this.name = "terminal" + x;                 this.autosize = false;                  bitmap resized = new bitmap(properties.resources.shapeterminal, new size(this.width, this.height));                 this.image = globals.changecolor(resized, color.yellow);                  this.text = this.name;                 this.textalign = contentalignment.middlecenter;             }      }  } 

here color changing algorithm use (found on stackoverflow well):

namespace pf2 {     public static class globals     {         public static bitmap changecolor(bitmap scrbitmap, color newcolor)         {             color actualcolor;             bitmap newbitmap = new bitmap(scrbitmap.width, scrbitmap.height);             (int = 0; < scrbitmap.width; i++)             {                 (int j = 0; j < scrbitmap.height; j++)                 {                     actualcolor = scrbitmap.getpixel(i, j);                     if (actualcolor.a > 150)                         newbitmap.setpixel(i, j, newcolor);                     else                         newbitmap.setpixel(i, j, actualcolor);                 }             }             return newbitmap;         }     } } 

and finally, how call class on form

int x = 0; private void btnterminal_click(object sender, eventargs e) {     terminal newsymbol = new terminal();      newsymbol.createterminal(x);     newsymbol.parent = tabpage1;      newsymbol.location = new point(newsymbol.width * x + 4, 0);     x++; } 

this how image looks whenever don't apply color changing algorithm. sets default image located in resources folder.

algo not applied

this how image looks whenever apply color changing algorithm. want apply anti-aliasing make edges smooth original don't know how.

algo applied

i stumbled upon interpolation while working on can't make work either. appreciate if me solve problem minimal changes in code. alternative ways long doesn't involve 3rd party software. thank much.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -