C# zoom problems

  • Thread starter Thread starter btb900
  • Start date Start date
B

btb900

Guest
All,

I am still having problem with Zoom. I make a small program, that when I click, it zooms in to a picture. the problem I am having is after I zoom the 1st time getting the right values to do the next zoom in a new location I did not zoom to the place place. This is because I am get the back the round location when I click. I tried doing a slope of a line equation, but it is still not working.

here is my code:


private void pictureBox1_Click(object sender, EventArgs e)
{
MouseEventArgs arg = (MouseEventArgs)e;



if (zoomFactor > 15)
{
zoomFactor = 15;
return;

}

float M = zoomFactor - 1;
float Bx = arg.Location.X - (M * Xclick);
float By = arg.Location.Y - (M* yclick);
float NewX = (arg.Location.X - Bx) /M;
float NewY = (arg.Location.Y - By) /M;

if (zoomFactor == 1)
{
NewX = arg.Location.X;
}

if (zoomFactor == 1)
{
NewY = arg.Location.Y;
}

Xclick = NewX;
yclick = NewY;



CalXTXT.Text = Convert.ToString(NewX);
CalYTXT.Text = Convert.ToString(NewY);


zoomFactor = zoomFactor * 1.5F;
imagex = Xclick * (-1) * (zoomFactor - 1F);
imagey = yclick * (-1) * (zoomFactor - 1F);

imgWidthTXT.Text = Convert.ToString(pictureBox1.Width * zoomFactor);
imgHeightTXT.Text = Convert.ToString(pictureBox1.Height * zoomFactor);


imgWidth = pictureBox1.Width * zoomFactor;
imgHeight = pictureBox1.Height * zoomFactor;



// Zoom(zoom, ImageX, ImageY);
Updatenow = true;
Panflag = false;
RecalcImage = true;
pictureBox1.Refresh();
}






private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (Updatenow)
{
Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
Pen borderPen = new Pen(borderColor, 1);




// g.DrawRectangle(borderPen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
if (RecalcImage)
{
if (Panflag)
{
Console.WriteLine(" Zoom Factor is " + zoomFactor);
if (rect.Width < imgWidth)
imagex = (zoomPointX * (-1) * (zoomFactor - 1));
else
imagex = (float)(rect.Width - imgWidth) / 2;

if (rect.Height < imgHeight)
imagey = (zoomPointY * (-1) * (zoomFactor - 1));
else
imagey = (float)(rect.Height - imgHeight) / 2;

Panflag = false;
}



g.DrawImage(currentFrame, imagex, imagey, imgWidth, imgHeight);
// currentFrame = (Bitmap) pictureBox2.Image; ;
Updatenow = false;
}

}

}







Can some one help me ?

Continue reading...
 
Back
Top