开发者

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

开发者 https://www.devze.com 2023-02-01 20:35 出处:网络
When I try to draw an image over another one using Graphics library C# it scale the small one and cover the first one:

When I try to draw an image over another one using Graphics library C# it scale the small one and cover the first one:

  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.FillRec开发者_运维问答tangle(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
    }


Have this instead:

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

This should draw the image in the "proper" place without stretching it.


look at draw on image

insteed DrawString you should use DrawImage

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号