Question

Je veux être en mesure d'enregistrer une image bitmap avec le texte à partir d'un fichier texte alors quand je l'ouvre à la fois le texte et le fichier bitmap ouvert et peut être consulté à une date ultérieure. Ceci est mon code actuel pour l'enregistrement d'une image bitmap:

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

Alors je en ai besoin pour enregistrer le texte dans une étiquette appelée ExtraNotes et être en mesure d'ouvrir l'image dans le picturebox (capturebox) et le texte de l'étiquette à nouveau. S'il vous plaît Aide,

Merci

Était-ce utile?

La solution

brossera un texte rugueux (vous pouvez le faire plus joli):

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

    }

Il suffit d'appeler

DrawSomethingToBitmap(bmp, lblMyLabel.Text);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top