Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Posted
Updated 14-Oct-12 1:35am
v3
Comments
Sergey Alexandrovich Kryukov 12-Oct-12 13:22pm    
To avoid confusion, please change the tag C++ to C++/CLI.
--SA
christmars 14-Oct-12 7:35am    
thanks for your advice!

1 solution

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:


I should also note that this is too much for PictureBox — this class does not help you, just presents some extra hassles, eats up some extra resource and your development time, nothing else. You should better draw immediately on some control, using the event Paint or overriding the virtual method OnPaint. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^];
and also:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

—SA
 
Share this answer
 
Comments
christmars 14-Oct-12 7:42am    
thanks a lot! I'm reading your past answers.
Sergey Alexandrovich Kryukov 14-Oct-12 23:09pm    
You are welcome.
As this should solve your problem (even with PictureBox), please accept the answer formally (green button) -- thanks.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900