Emy*_*man 2 .net c# 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
}
Run Code Online (Sandbox Code Playgroud)
改成这样:
g.DrawImage(theImage2, 0, 0, theImage2.Width, theImage2.Height);
Run Code Online (Sandbox Code Playgroud)
这应该在“适当”的位置绘制图像而不拉伸它。
| 归档时间: |
|
| 查看次数: |
5426 次 |
| 最近记录: |