C#實(shí)現(xiàn)繪制隨機(jī)噪點(diǎn)和直線
實(shí)踐過程
效果


代碼
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);
//畫圖片的背景噪音線
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);
}
//畫圖片的前景噪音點(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()));
}
//畫圖片的邊框線
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)的簡(jiǎn)單整數(shù)四則運(yùn)算計(jì)算器功能示例
這篇文章主要介紹了C#實(shí)現(xiàn)的簡(jiǎn)單整數(shù)四則運(yùn)算計(jì)算器功能,涉及C#界面布局、事件響應(yīng)及數(shù)值運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09
C#實(shí)現(xiàn)簡(jiǎn)單屏幕監(jiān)控的方法
這篇文章主要介紹了C#實(shí)現(xiàn)簡(jiǎn)單屏幕監(jiān)控的方法,涉及C#的圖標(biāo)隱藏及屏幕截圖等技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
詳談C# 圖片與byte[]之間以及byte[]與string之間的轉(zhuǎn)換
下面小編就為大家?guī)硪黄斦凜# 圖片與byte[]之間以及byte[]與string之間的轉(zhuǎn)換。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
Unity3d實(shí)現(xiàn)無限循環(huán)滾動(dòng)背景
這篇文章主要為大家詳細(xì)介紹了Unity3d實(shí)現(xiàn)無限循環(huán)滾動(dòng)背景,一個(gè)完整的商店廣告牌組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
C#調(diào)用C++的dll兩種實(shí)現(xiàn)方式(托管與非托管)
這篇文章主要介紹了C#調(diào)用C++的dll兩種實(shí)現(xiàn)方式(托管與非托管),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08
C# 中的委托與事件實(shí)現(xiàn)靈活的回調(diào)機(jī)制(應(yīng)用場(chǎng)景分析)
委托提供了一種類型安全的方式將方法作為參數(shù)傳遞,而事件則允許對(duì)象通知其他對(duì)象發(fā)生了某些事情,這篇文章主要介紹了C# 中的委托與事件實(shí)現(xiàn)靈活的回調(diào)機(jī)制,需要的朋友可以參考下2024-12-12
word ppt excel文檔轉(zhuǎn)換成pdf的C#實(shí)現(xiàn)代碼
這篇文章主要介紹了word ppt excel文檔轉(zhuǎn)換成pdf的C#實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2014-01-01

