最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2023年01月05日 11:06:20   作者:芝麻粒兒  
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)繪制隨機(jī)噪點(diǎn)和直線,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下

實(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)文章

最新評(píng)論

云阳县| 侯马市| 涿州市| 保靖县| 临颍县| 康乐县| 彭州市| 宝应县| 景德镇市| 左云县| 达尔| 潜江市| 凌海市| 融水| 宜春市| 海阳市| 应城市| 石家庄市| 西宁市| 松江区| 姚安县| 宝坻区| 东城区| 永康市| 鄯善县| 边坝县| 牙克石市| 琼海市| 鹤峰县| 海门市| 五华县| 曲麻莱县| 永安市| 宜昌市| 合水县| 亚东县| 德令哈市| 寿宁县| 肥城市| 乐东| 勐海县|