简体   繁体   中英

C# Bitmap To PictureBox is not working well

I'm trying to make some gradient & preview it in a pictureBox without saving but it seems not working:

        if (isChanged == true)
        {
                re = new Rectangle(0, 0, int.Parse(textBox5.Text), int.Parse(textBox4.Text));
                currectBrush = new System.Drawing.Drawing2D.LinearGradientBrush(re, System.Drawing.ColorTranslator.FromHtml("#FC00FF"), System.Drawing.ColorTranslator.FromHtml("#00DBDE"), -45f); ;
                bitmap = new Bitmap(int.Parse(textBox5.Text), int.Parse(textBox4.Text));
                using (bitmap)
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    currectBrush = new System.Drawing.Drawing2D.LinearGradientBrush(re, System.Drawing.ColorTranslator.FromHtml(textBox1.Text), System.Drawing.ColorTranslator.FromHtml(textBox2.Text), int.Parse(textBox3.Text));

                    graphics.FillRectangle(currectBrush, re);
                    pictureBox1.Image = bitmap;

                }
                isChanged = false;
        }

And this is what pictureBox looks like after running this part of code:

删除此行,因为它会处理资源

using (bitmap)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM