我tyring把點添加到一個地圖。無論該地圖上有多少針腳,每個針腳都會獲得自己的顏色。我想只改變色調如何將位圖更改爲另一種隨機顏色?
我使用的模板PNG,看起來像這樣
我想創建功能,當一個新的點出現這個文件會得到隨機的顏色。
我該怎麼做?
代碼下面我的工作 - 我無法弄清楚如何在矩陣扔隨機值輸出間隔足夠遠的顏色齶任何良好的色彩
private Bitmap ColorMyPin()
{
Image imgPicture = Properties.Resources.green_MarkerBlank;
Bitmap bmp = new Bitmap(imgPicture.Width, imgPicture.Height);
ImageAttributes iaPicture = new ImageAttributes();
ColorMatrix cmPicture = new ColorMatrix(new float[][]
{
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0}, <-- //Hard part where do i throw random() values at
new float[] {0, 0, 0, 0, 0},
new float[] {0, 0, 0, 0, 0}
});
// Set the new color matrix
iaPicture.SetColorMatrix(cmPicture);
// Set the Graphics object from the bitmap
Graphics gfxPicture = Graphics.FromImage(bmp);
// New rectangle for the picture, same size as the original picture
Rectangle rctPicture = new Rectangle(0, 0, imgPicture.Width, imgPicture.Height);
// Draw the new image
gfxPicture.DrawImage(imgPicture, rctPicture, 0, 0, imgPicture.Width, imgPicture.Height, GraphicsUnit.Pixel, iaPicture);
return bmp;
}
後
那麼什麼是你的問題?它看起來像你正在得到你需要的結果? – 2013-03-19 21:10:23
@RowlandShaw我用GIMP這樣做。我試圖在c#中以編程方式執行此操作。我不知道如何改變顏色又單獨色調只 – stackoverflow 2013-03-19 21:12:21
看看這個答案,http://stackoverflow.com/a/383305/525138代碼,他們正在改變一個JPG,但應沿同樣的線條 – Dutts 2013-03-19 21:14:49