I want to be able to save a bitmap image with text from a text file so when i open it both the text and bitmap file open and can be viewed at a later date. This is my current code for saving a bitmap image:
{
//Show a save dialog to allow the user to specify where to save the image file
using (SaveFileDialog dlgSave = new SaveFileDialog())
{
dlgSave.Title = "Save Image";
dlgSave.Filter = "Bitmap Images (*.bmp)|*.bmp|All Files (*.*)|*.*";
if (dlgSave.ShowDialog(this)开发者_如何学JAVA == DialogResult.OK)
{
//If user clicked OK, then save the image into the specified file
using (Bitmap bmp = new Bitmap(capturebox.Width, capturebox.Height))
{
capturebox.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(dlgSave.FileName);
}
}
}
}
So i need it to save the text in a label called ExtraNotes and then be able to open the image in the picturebox (capturebox) and the text in the label again. Please Help,
Thanks
This will draw a rough text (you can make it prettier):
static void DrawSomethingToBitmap(Image img, string text)
{
Graphics g = Graphics.FromImage(img);
g.DrawString(text, SystemFonts.DefaultFont, Brushes.Gray,
img.Width/2, img.Height/2);
}
Just call
DrawSomethingToBitmap(bmp, lblMyLabel.Text);
精彩评论