繁体   English   中英

如何使用图形库C#在图像上绘制小图像?

[英]How can I draw a small image over an image using Graphics library C# ?

当我尝试使用图形库C#在另一幅图像上绘制图像时,它会缩放较小的图像并覆盖第一个图像:

  public Form1()
    {   
        //InitializeComponent();
        read_file();
        InitializeComponent1();
        SetStyle(ControlStyles.Opaque, true);
        // theImage = new Bitmap("F:/4th year/1st Term/sensor network/proj/reconstructscene/reconstructscene/images/tryImage.jpg");
        theImage2 = new Bitmap("F:/4th year/1st Term/sensor network/proj/reconstructscene/reconstructscene/images/1.jpg");
        // theImage = new Bitmap(newImage);
        theImage = new Bitmap("F:/4th year/1st Term/sensor network/proj/reconstructscene/reconstructscene/images/tryImage.jpg");
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        //e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
        //e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
        //e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; 
          g.DrawImage(theImage, ClientRectangle);
        // Create pen.
        g.FillRectangle(new SolidBrush(Color.Red), 50, 50, 50, 50);
        RectangleF recto = new System.Drawing.RectangleF(50, 50, 50, 50);
        Pen blackPen = new Pen(Color.Black,1);

        g.DrawRectangle(blackPen, 50, 50, 50, 50);
        g.DrawImage(theImage2, ClientRectangle); //this will cover the 1st one
    }

改成这样:

g.DrawImage(theImage2, 0, 0, theImage2.Width, theImage2.Height);

这应该在“适当”的位置绘制图像而不拉伸它。

画在图像上

insteed DrawString你应该使用DrawImage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM