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

标签 c# .net graphics drawimage

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

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

关于c# - 如何使用图形库 C# 在图像上绘制小图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4554075/

相关文章:

C#:如何使用类型转换器本地化枚举

c# - 当用户增加 SQL 数据库大小时接收通知

.net - 多线程循环卡住ui

.net - 如何使用区域在 razor 组件库中使用 blazor 服务器端?

c++ - Direct2D - 截图

c# - 我如何在 "Create New Screen"上创建一个按钮,它将在 Lightswitch 中保存、关闭和启动一个新的 "Create New Screen"?

c# - 不能在 Socket.BeginConnect() 的回调函数中使用断点

.net - 从 DataTemplate 访问父 DataContext

c# - 基本位图字体渲染

delphi - 在德尔福 Canvas 中绘制图片的非矩形部分