Home > Net >  How to adapt to the picturebox c # graphics drawn Bitmap Bitmap size?
How to adapt to the picturebox c # graphics drawn Bitmap Bitmap size?

Time:12-23

Graphics g=pictureBox2. CreateGraphics ();
Right to Lear (Color. White);
//to copy the source area
A Rectangle the 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.D rawImage (pictureBox1. Image, 0, 0, the rect, GraphicsUnit. Pixel);

Will pictureBox1. The rectangular area in the Image display to pictureBox2, but can't put the content of the drawing automatically adapt to the size of the pictureBox2, the great god, please help, thank you

CodePudding user response:

Should be placed pictureBox2 method of Paint a picture
 
Private void pictureBox2_Paint (object sender, PaintEventArgs e)
{
Graphics g=um participant raphics;
Right to Lear (Color. White);
A Rectangle the rect=new Rectangle (0, 0, 100, 100);//to copy the source area
G.D rawImage (pictureBox1. Image, 0, 0, the rect, GraphicsUnit. Pixel);
}

CodePudding user response:

The size of the adaptive into pictureBox2:
 
Private void pictureBox2_Paint (object sender, PaintEventArgs e)
{
Graphics g=um participant raphics;
//right to Lear (Color. White);
A Rectangle the rect=new Rectangle (0, 0, pictureBox2. Width, pictureBox2 Height);//target area

ImageAttributes ImgAtt=new ImageAttributes ();
ImgAtt. SetWrapMode (System. Drawing. Drawing2D. WrapMode. TileFlipXY);
G.D rawImage (pictureBox1. Image, the rect,
0, 0, 100, 100,//to copy the source area
GraphicsUnit Pixel, ImgAtt);
}
  •  Tags:  
  • C#
  • Related