سؤال

مرحبًا ، أحاول إظهار صورة لملفاتي في PreviWew Pane ، يمكنني عرض صورة ملفي ، لكنني عالق في الجزء الذي أحتاج فيه إلى كتابة بعض النص على الصورة قبل إضافته إلى Pane 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();

فقط الصورة التي تستوعب وليس النص ، أي فكرة عما قد أفتقده. شكرًا

هل كانت مفيدة؟

المحلول

تضييقها أيضًا:

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