C# Bitmap To PictureBox 运行不正常
C# Bitmap To PictureBox is not working well
我正在尝试制作一些渐变并在不保存的情况下在 pictureBox 中预览它,但它似乎不起作用:
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;
}
这就是 pictureBox 在 运行 这部分代码之后的样子:
删除此行,因为它会处理资源
using (bitmap)
我正在尝试制作一些渐变并在不保存的情况下在 pictureBox 中预览它,但它似乎不起作用:
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;
}
这就是 pictureBox 在 运行 这部分代码之后的样子:
删除此行,因为它会处理资源
using (bitmap)