2

当我尝试使用图形库 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
    }
4

2 回答 2

5

改为:

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

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

于 2010-12-29T12:32:30.457 回答
-1

看看在图像上绘制

实际上 DrawString 你应该使用 DrawImage

于 2010-12-29T12:37:50.163 回答