Graphics g = pictureBox2.CreateGraphics();
g.Clear(Color.White);
//要復制的源區域
Rectangle rect = new Rectangle(Math.Min((int)(start.X * Widthproportion), (int)(end.X * Widthproportion)), Math.Min((int)(start.Y * Heightproportion), (int)(end.Y * Heightproportion)), Math.Abs((int)(start.X * Widthproportion) - (int)(end.X * Widthproportion)), Math.Abs((int)(start.Y * Heightproportion) - (int)(end.Y * Heightproportion)));
g.DrawImage(pictureBox1.Image, 0, 0, rect, GraphicsUnit.Pixel);
將pictureBox1.Image中的矩形區域顯示到pictureBox2中,但是沒辦法把繪制的內容自動適應成pictureBox2的大小,請大神們幫幫忙,謝謝
uj5u.com熱心網友回復:
要放在pictureBox2的Paint方法里畫
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.White);
Rectangle rect = new Rectangle(0, 0, 100, 100); //要復制的源區域
g.DrawImage(pictureBox1.Image, 0, 0, rect, GraphicsUnit.Pixel);
}
uj5u.com熱心網友回復:
自適應成pictureBox2的大小:
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// g.Clear(Color.White);
Rectangle rect = new Rectangle(0, 0, pictureBox2.Width, pictureBox2.Height); //目標區域
ImageAttributes ImgAtt = new ImageAttributes();
ImgAtt.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
g.DrawImage(pictureBox1.Image, rect,
0, 0, 100, 100, //要復制的源區域
GraphicsUnit.Pixel, ImgAtt);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/238837.html
標籤:C#
上一篇:.net core專案訪問控制器報錯: the application completed without reading the entire request
