保存带有标签的图片(picturBox的图像) [英] Save a picture(Image of a picturBox) with a label on it

查看:128
本文介绍了保存带有标签的图片(picturBox的图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我要执行以下功能:

使用button_click加载图片,该图片应该在图片的左下方有一个嵌入的标签.然后,应将此新"图片(图片+标签)保存在文件中.

我在左下方的图像上轻松制作了标签.标签应显示系统日期和时间.
我用于加载图片并更改label1值的代码是:

Hello!

I want to make following function:

With a button_click to load a picture, which should has a embeded label at the bottom left of the picture. And then this "new" picture (picture + label) should be saved in a file.

I made the label easily over the image at bottom left. The Label should show the system date and time.
My code for loading the picture and change the value of label1 is:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
 label1->Text = Convert::ToString(System::DateTime::Now);

 pictureBox1->Image = gcnew Bitmap( "H:\\picture1.jpg");

 //How to save this two in a file?
}

现在,我在窗口中有带有日期时间标签的图片.我想将这两个文件另存为新的图片文件.
我该怎么实现?

感谢您的回答!

Now I have the picture with the datetime label in the window. And I want to save these two together as a new picture file.
How can I realize this?

I appreciate your answers!

推荐答案

您可以使用绝对定位(Label::Top).但是,这不会为您提供透明的标签背景(与WPF不同,透明度是System.Windows.Forms的普遍问题).

您也可以在图像本身上绘制.算法是这样的:
You could simply impose a Label instance on top of the PictureBox control, using absolute positioning (Label::Top, Label::Left). However, this won''t give you transparent label background (transparency is a general problem of System.Windows.Forms, unlike WPF).

You can also draw on the image itself. The algorithm is this:
  • Get an instance of System.Drawing::Graphics::FromImage: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx[^].
  • Draw what you need on the image using this instance of Graphics, Graphics::DrawString, see http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].
  • Dispose this instance of Graphics.


这篇关于保存带有标签的图片(picturBox的图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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