【问题标题】:C# Picturebox loaded PNG save with Picturebox Background ColourC# Picturebox加载的PNG保存与Picturebox背景颜色
【发布时间】:2020-09-09 13:50:18
【问题描述】:

我需要用图片框背景颜色保存图片框加载的 png 文件。

这些我都试过了。

但结果显示为空白图像。

帮帮我..

private void bunifuThinButton24_Click(object sender, EventArgs e)
    {
        Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());
        bmp1.Save(@"C:\Users\...\New folder4\ xx.jpg");
    }

【问题讨论】:

  • pbox.DrawToBitmap 会做到这一点。或者您可以使用 g.drawimage 将 g.drawimage 清除到 someColor 的新图像上,g fromBitmap - 另外:永远不要使用control.CreateGraphics!永远不要尝试缓存 Graphics 对象!使用Graphics g = Graphics.FromImage(bmp) 或在控件的Paint 事件中使用e.Graphics 参数绘制到Bitmap bmp
  • 知道了。谢谢朋友。

标签: c# colors background picturebox


【解决方案1】:

Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics()); 以pictureBox1 的图形对象的分辨率创建一个新的空白位图图像。你需要在这个位图中绘制你的图片框。您可以使用图片框的 DrawToBitmap 函数来做到这一点。

void bunifuThinButton24_Click(object sender, EventArgs e)
    {
        Bitmap bmp1 = new Bitmap(pictureBox1.Width, pictureBox1.Height, pictureBox1.CreateGraphics());

        // fill in bitmap with the picturebox's backcolor
        using (Graphics g = Graphics.FromImage(bmp1))
            {
                using (Brush drawBrush = new SolidBrush(pictureBox1.BackColor))
                {
                    g.FillRectangle(drawBrush, new Rectangle(0, 0, bmp1.Width, bmp1.Height));
                }
            }

        // draw picturebox on bitmap
        pictureBox1.DrawToBitmap(bmp1, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

        bmp1.Save(@"C:\Users\...\New folder4\ xx.jpg");
    }

【讨论】:

    猜你喜欢
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    相关资源
    最近更新 更多