Pregunta

hola estoy tratando de mostrar la imagen de mi archivo en el panel previwew soy capaz de mostrar la imagen de mi archivo, pero estoy atascado en la parte donde tengo que escribir algún texto en la imagen antes de añadirlo al panel de vista previa.

// create an image object, using the filename we just retrieved
            String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
            //file.CreationTime.ToString();
            //------------------------------------
            //Load the Image to be written on.

            Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
            Graphics graphicImage = Graphics.FromImage(bitMapImage);
            graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
            graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
            //Save the new image to the response output stream.
            bitMapImage.Save(strImageFile, ImageFormat.Png);


            //------------------------------------
            // Create a picture box control
            PictureBox p = new PictureBox();
            p.Dock = DockStyle.Fill;
            p.Image = bitMapImage;
            //p.Image = System.Drawing.Image.FromFile(strImageFile);
            p.SizeMode = PictureBoxSizeMode.Zoom;
            Controls.Add(p);
            //graphicImage.Dispose();
            //bitMapImage.Dispose();

Sólo el appease imagen y no el texto, alguna idea de lo que podría hacer falta. gracias

¿Fue útil?

Solución

reducirlo también:

PictureBox p = new PictureBox();
            // create an image object, using the filename we just retrieved
            String strImageFile = file.FullName.Substring(0, file.FullName.Length - 3) + "jpg";
            Bitmap bitMapImage = new System.Drawing.Bitmap(strImageFile);
            Graphics graphicImage = Graphics.FromImage(bitMapImage);
            graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            graphicImage.DrawString("AWESOME!", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(100, 250));
            graphicImage.DrawImage(bitMapImage, new Rectangle(205, 0, 200, 200), 0, 0, bitMapImage.Width, bitMapImage.Height, GraphicsUnit.Pixel);
            p.Image = bitMapImage;
            p.Dock = DockStyle.Fill;

            Controls.Add(p);

Pero estoy consiguiendo una excepción en

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top