質問

こんにちは私は私のファイルの画像をpreviwewペインに表示しようとしています。ファイルの画像を表示することができますが、プレビューペインに追加する前に画像にテキストを書く必要がある部分に貼り付けられています。

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

画像だけがテキストではなく、私が欠けている可能性のあるアイデアをなだめます。ありがとう

役に立ちましたか?

解決

それを絞り込む:

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

しかし、私は例外を取得しています

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top