如何保存在我的Pictrebox中添加的所有Picturebox控件的一个图像? [英] How Do I Save One Image Of All Picturebox Controls Which Added In My Pictrebox?

查看:83
本文介绍了如何保存在我的Pictrebox中添加的所有Picturebox控件的一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PictureBox picture00 = new PictureBox();

picture00.SizeMode = PictureBoxSizeMode.StretchImage;

picture00.Image = new Bitmap(Application.StartupPath +\\\ \\ pic.jpg);

picture00.Location = new System.Drawing.Point(145,172);

picture00.Size = new System.Drawing.Size( 88,130);

pictureBox1.Controls.Add(picture00);

解决方案

假设保存整个的图像Panel的视觉内容是您的目标:

  //  确保您包括这些: 
使用 System.Drawing;
使用 System.Drawing.Imaging;

// 假设有一个名为'SavePanel1Contents 的按钮
< span class =code-keyword> private void SavePanel1Contents_Click( object sender,EventArgs e )
{
int width = panel1.Width;
int height = panel1.Height;

位图bitMap = new 位图(宽度,高度);

panel1.DrawToBitmap(bitMap, new 矩形( 0 0 ,宽度,高度));

// 使用.png格式:还有许多其他格式可以保存为
bitMap.Save( @ C:\ Users \YourUserName \Desktop \ TestSaveImageOfPanel1.png,ImageFormat.Png);
}


除了解决方案1:



你不应该使用class PictureBox 。这种控制纯粹是多余的,旨在帮助开发人员处理一些最简单的情况。如果你在你的情况下使用它,它将没有帮助,只会迫使你使用一些额外的资源,浪费开发时间。该怎么办?请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

画一个矩形C# [ ^ ],

如何从旧图纸中清除面板 [ ^ ],

什么样的p Layful方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



-SA

PictureBox picture00 = new PictureBox();
picture00.SizeMode = PictureBoxSizeMode.StretchImage;
picture00.Image = new Bitmap(Application.StartupPath + "\\pic.jpg");
picture00.Location = new System.Drawing.Point(145, 172);
picture00.Size = new System.Drawing.Size(88, 130);
pictureBox1.Controls.Add(picture00);

解决方案

Assuming that saving an image of the entire visual contents of the Panel is your goal:

// be sure you include these:
using System.Drawing;
using System.Drawing.Imaging;

// assume there's a Button named 'SavePanel1Contents
private void SavePanel1Contents_Click(object sender, EventArgs e)
{
    int width = panel1.Width;
    int height = panel1.Height;

    Bitmap bitMap = new Bitmap(width, height);

    panel1.DrawToBitmap(bitMap, new Rectangle(0, 0, width, height));

    // using .png format here: there are many other formats you can save as
    bitMap.Save(@"C:\Users\YourUserName\Desktop\TestSaveImageOfPanel1.png", ImageFormat.Png);
}


In addition to Solution 1:

You should not use the class PictureBox. This control is purely redundant, designed to help developers in some simplest cases. If you use it in your case, it won't be helpful, will only force your to use some extra resources and waste development time. What to do? Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA


这篇关于如何保存在我的Pictrebox中添加的所有Picturebox控件的一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆