I have 2 pictureBoxes on my Form. In the right pictureBox I can zoom and pan an image. The illustration on the left shows only the image. Unfortunately I can‘t copy the zoomed image from pictureBox1(right) into pictureBox2. How should i do that? I’m thankful for any hint!
public Form1()
{
InitializeComponent();
string imgFile = @"C:\Users\Pictures\Clock.jpg";
img = Image.FromFile(imgFile);
Graphics g = this.CreateGraphics();
zoom = ((float)pictureBox1.Width / (float)img.Width) * (img.HorizontalResolution / g.DpiX);
pictureBox1.Paint += new PaintEventHandler(ImageBox_Paint);
}
private void ImageBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.ScaleTransform(zoom, zoom);
e.Graphics.DrawImage(img, imgX, imgY);
}
private void Button1_Click(object sender, EventArgs e)
{
Bitmap newbmp= new Bitmap(pictureBox2.ClientSize.Width,pictureBox2.ClientSize.Height);
using (Bitmap oldbmp = new Bitmap(img, pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height))
{
using (Graphics g = Graphics.FromImage(newbmp))
{
g.DrawImage(oldbmp, new Rectangle(0, 0,
pictureBox2.ClientSize.Width,pictureBox2.ClientSize.Height));
}
}
pictureBox2.Image = newbmp;
}