views:

13

answers:

1

hi i am trying to show image of my file in previwew pane i am able to display the image of my file but i am stuck in the part where i need write some text on the image before adding it to preview pane.

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

Only the image appease and not the text, any idea what i might be missing. thanks

A: 

Narrow it down too:

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

But i am getting an exception on

jaminator
yeah its working
jaminator