Domanda

ciao io sto cercando di mostrare l'immagine del mio file nel riquadro previwew sono in grado di visualizzare l'immagine del mio file, ma io sono bloccato nella parte in cui ho bisogno di scrivere un testo su l'immagine prima di aggiungerlo al riquadro di anteprima.

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

Solo l'placare immagine e non il testo, qualsiasi idea di cosa potrei mancare. grazie

È stato utile?

Soluzione

restringere il campo troppo:

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

Ma sto un'eccezione

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top