Thursday 15 July 2010

c# - Color List In A Image -



c# - Color List In A Image -

i need used 30 color list image... there alot of color tone's , can't main colors. illustration image has reddish color can't reddish color.

what can do?

dictionary<string,int> d = new dictionary<string, int>(); bitmap bmp = (bitmap)bitmap.fromfile("c:\\test.jpg"); (int x = 0; x < bmp.width; x++) { (int y = 0; y < bmp.height; y++) { color c = bmp.getpixel(x, y); var hexcolor = c.r.tostring("x") + c.g.tostring("x") + c.b.tostring("x"); if (d.containskey(hexcolor)) { d[hexcolor] = ++d[hexcolor]; } else { d.add(hexcolor, 1); } } } var items = (from pair in d orderby pair.value descending select pair); system.io.streamwriter file = new system.io.streamwriter("c:\\colors.html",false); foreach (var v in items) { file.writeline("<div style='width:50px;height:50px;float:left;margin-right:10px;background-color:#" + v.key + "'>&nbsp;</div>"); } file.close();

rgb composed of 3 primary colors: red, green, blue. each of them has value in range 0-255. colors rgb (0,255,0), rgb (0,254,0), rgb (0,253,0), rgb (2,254,2) same, in fact different. perhaps should add together tolerance range of colors.

c# image gdi

No comments:

Post a Comment