Capture ecran richTextBox = image toute noir

Neroxs - Modifié par Neroxs le 30/07/2014 à 08:42
 Neroxss - 30 juil. 2014 à 09:43
Bonjour,
J'essais de récuperé l'image d'un richTextox via DrawToBitmap mais l'image est toute noir.

code:

Bitmap bmp = new Bitmap(box.ClientRectangle.Width, box.ClientRectangle.Height);
            using (Graphics G = Graphics.FromImage(bmp))
            {
                using (SolidBrush brush = new SolidBrush(Color.FromArgb(1, 1, 1)))
                {
                    
                    G.FillRectangle(SystemBrushes.Control, 0, 0, box.Width, box.Height);
                   
                }
            }
            
            box.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
            bmp.Save("image.jpg", ImageFormat.Jpeg);


Quelqu'un pourait il me dir ce qu'il ne va pas ?
Merci.

2 réponses

Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
30 juil. 2014 à 09:20
Bonjour,

j'avais trouvé ce code il y a un moment.
Ca marche pour mon utilisation, mais je n'ai jamais essayé avec un RichTextBox

    public static class ImpressionEcran
    {
        [DllImportAttribute("gdi32.dll")]
        private static extern bool BitBlt(
        IntPtr hdcDest,
        int nXDest,
        int nYDest,
        int nWidth,
        int nHeight,
        IntPtr hdcSrc,
        int nXSrc,
        int nYSrc,
        int dwRop);

        public static Bitmap CaptureControl(Control control)
        {
            Bitmap controlBmp;
            using (Graphics g1 = control.CreateGraphics())
            {
                controlBmp = new Bitmap(control.Width, control.Height, g1);
                using (Graphics g2 = Graphics.FromImage(controlBmp))
                {
                    IntPtr dc1 = g1.GetHdc();
                    IntPtr dc2 = g2.GetHdc();
                    BitBlt(dc2, 0, 0, control.Width, control.Height, dc1, 0, 0, 13369376);
                    g1.ReleaseHdc(dc1);
                    g2.ReleaseHdc(dc2);
                }
            }

            return controlBmp;
        }
    }

0
Merci pour ton aide , mais l'image du richTextBox est toujours noir ...
Il y a vraiment quelque chose qui m'échappe...
0
Rejoignez-nous