0

我希望能够使用文本文件中的文本保存位图图像,因此当我打开它时,文本和位图文件都会打开并且可以在以后查看。这是我当前保存位图图像的代码:

{
    //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) == 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);
            }
        }
    }
}

所以我需要它将文本保存在一个名为 ExtraNotes 的标签中,然后能够打开图片框(捕获框)中的图像和标签中的文本。请帮忙,

谢谢

4

1 回答 1

4

这将绘制一个粗略的文本(你可以让它更漂亮):

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);

    }

打电话

DrawSomethingToBitmap(bmp, lblMyLabel.Text);
于 2010-11-29T17:18:11.740 回答