Have resize the image to fit the picture box (for other purpose). now i tried to zoom in the image and i succeed on it. but my problem is when i zoom the image the image get zoomed and image moves toward right.
if I use zero instead of c(in below code) the image placed at the left corner and when zoomed it starts from there. but i need to place the image in that particular location.
How can zoom the image without changing the position of the image.
Thanks in advance.
C#
//sz1 = (800, 600)private Image resizeimage(Image my, Size sz1)
{
double ratio = 0d;
double myThumbWidth = 0d;
double myThumbHeight = 0d;
Bitmap bp;
int c;
int d;
if ((my.Width / Convert.ToDouble(sz1.Width)) > (my.Height /
Convert.ToDouble(sz1.Height)))
ratio = Convert.ToDouble(my.Width) / Convert.ToDouble(sz1.Width);
else ratio = Convert.ToDouble(my.Height) / Convert.ToDouble(sz1.Height);
myThumbHeight = Math.Ceiling(my.Height / ratio);
myThumbWidth = Math.Ceiling(my.Width / ratio);
Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
bp = new Bitmap(sz1.Width, sz1.Height);
c = (sz1.Width - thumbSize.Width) / 2;
d = (sz1.Height - thumbSize.Height);
System.Drawing.Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
rect = new Rectangle(c, d, thumbSize.Width, thumbSize.Height);
g.DrawImage(my, rect, 0, 0, my.Width, my.Height, GraphicsUnit.Pixel);
if (f == false)
{
sz = bp.Size;
pictureBox1.Size = sz;
}
rect = new Rectangle(0, 0, 0, 0);
return (bp);
// this will trigged when clicked on the picture boxpublicvoidZoomIn()
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
if (sz.Width >= c)
MessageBox.Show("Max ZoomIn");
else {
sz.Width += 50;
sz.Height += 50;
pictureBox1.Size = sz;
pictureBox1.Invalidate();
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
The image web viewer i am using now offers users five options for web image zooming, including, image zooming in and out, fitting image to doc viewer width, viewing whole image on doc viewer and viewing web image in original size. For detailed javascript codes, you can check out the online guides.
Nivas Sadashivam8 pointsPosted Jul 6, 2010, 10:40 PM EDT
Chestertonpdf Chesterton20 pointsPosted May 19, 2014, 8:02 PM EDT