C#實(shí)現(xiàn)繪制隨機(jī)噪點(diǎn)和直線
實(shí)踐過(guò)程
效果
代碼
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Bitmap image = new Bitmap(100, 22); Graphics g = Graphics.FromImage(image); try { //生成隨機(jī)生成器 Random random = new Random(); //清空?qǐng)D片背景色 g.Clear(Color.White); //畫(huà)圖片的背景噪音線 for (int i = 0; i < 2; i++) { Point tem_Point_1 = new Point(random.Next(image.Width), random.Next(image.Height)); Point tem_Point_2 = new Point(random.Next(image.Width), random.Next(image.Height)); g.DrawLine(new Pen(Color.Black), tem_Point_1, tem_Point_2); } //畫(huà)圖片的前景噪音點(diǎn) for (int i = 0; i < 100; i++) { Point tem_point = new Point(random.Next(image.Width), random.Next(image.Height)); image.SetPixel(tem_point.X, tem_point.Y, Color.FromArgb(random.Next())); } //畫(huà)圖片的邊框線 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); pictureBox1.Image = image; } catch { } } }
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { pictureBox1.Image = Image.FromFile(openFileDialog1.FileName); } } private void button2_Click(object sender, EventArgs e) { if (pictureBox1.Image != null) { Bitmap bt = new Bitmap(pictureBox1.Image); Graphics g = Graphics.FromImage(bt); g.DrawLine(new Pen(Color.Red, 40), new Point(0, bt.Height / 2), new Point(bt.Width, bt.Height / 2)); g.DrawLine(new Pen(Color.Red, 40), new Point(bt.Width / 2, 0), new Point(bt.Width / 2, bt.Height)); g.DrawLine(new Pen(Color.Red, 40), new Point(0, 0), new Point(bt.Width, bt.Height)); g.DrawLine(new Pen(Color.Red, 40), new Point(0, bt.Height), new Point(bt.Width, 0)); pictureBox1.Image = bt; } } }
到此這篇關(guān)于C#實(shí)現(xiàn)繪制隨機(jī)噪點(diǎn)和直線的文章就介紹到這了,更多相關(guān)C#繪制隨機(jī)噪點(diǎn) 直線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用C#實(shí)現(xiàn)Windows組和用戶(hù)管理的示例代碼
這篇文章主要介紹了使用C#實(shí)現(xiàn)Windows組和用戶(hù)管理的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01C# winform編程中響應(yīng)回車(chē)鍵的實(shí)現(xiàn)代碼
這篇文章主要介紹了C# winform編程中響應(yīng)回車(chē)鍵的實(shí)現(xiàn)代碼,既在窗口上響應(yīng)回車(chē)鍵事件的方法,需要的朋友可以參考下2014-08-08在C# WPF下自定義滾動(dòng)條ScrollViewer樣式的操作
這篇文章主要介紹了在C# WPF下自定義滾動(dòng)條ScrollViewer樣式的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01C#基礎(chǔ)之?dāng)?shù)組排序、對(duì)象大小比較實(shí)現(xiàn)代碼
C#基礎(chǔ)之?dāng)?shù)組排序、對(duì)象大小比較實(shí)現(xiàn)代碼,學(xué)習(xí)c#的朋友可以參考下。2011-08-08基于WebRequest.RegisterPrefix的使用詳解
本篇文章對(duì)WebRequest.RegisterPrefix的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05