Zoom Fo-Dicom

423 views
Skip to first unread message

Matias

unread,
Aug 2, 2013, 4:49:56 PM8/2/13
to fo-d...@googlegroups.com
Hi,

is there a function to perform Zoom to images?

I seem not to find one.

Thanks!

Mahesh Dubey

unread,
Aug 5, 2013, 7:16:50 AM8/5/13
to fo-d...@googlegroups.com
Scale property of DicomImage

Mahesh
Message has been deleted

Matias

unread,
Aug 5, 2013, 1:09:09 PM8/5/13
to fo-d...@googlegroups.com
Thanks Mahesh,

do you have a working example? I'm able to scale the image but not sure how to handle the zoom itself. If I scale the image, then, how do I retain the center and how I can "scroll" or move within the zoomed image?

Thanks!

Chris Horn

unread,
Aug 5, 2013, 5:58:24 PM8/5/13
to fo-d...@googlegroups.com
If your using WPF I would do the following:
                   
<Viewbox>
   
<Grid>
     
<Image x:Name="MainImage" />
   
</Grid>
</Viewbox>

then in your code create:
ScaleTransform _imageScaleTransform = new ScaleTransform();

// build transform group and add to main image
var transformGroup = new TransformGroup();
transformGroup
.Children.Add(_imageScaleTransform);
MainImage.RenderTransform = transformGroup;
MainImage.RenderTransformOrigin = new Point(0.5, 0.5);

then you can make the zoom happen on mouse events

private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
   
if (MainImage.IsMouseDirectlyOver)
   
{
        _rightButtonMouseCaptured
= true;
       
((UIElement) sender).CaptureMouse();
        _rightButtonScreenPosition
= mouseButtonEventArgs.GetPosition(this);
   
}
}

private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs)
{
   
#region Magnify

   
if (_rightButtonMouseCaptured)
   
{
       
var currentPositionRight = mouseEventArgs.GetPosition(this);
       
var rightDelta = currentPositionRight.Y - _rightButtonScreenPosition.Y;
       
if (rightDelta > 1)
       
{
            _imageScaleTransform
.ScaleX *= 1.1;
            _imageScaleTransform
.ScaleY *= 1.1;
       
}
       
else if (rightDelta <= -1)
       
{
            _imageScaleTransform
.ScaleX /= 1.1;
            _imageScaleTransform
.ScaleY /= 1.1;
       
}
        _rightButtonScreenPosition
= currentPositionRight;
       
return;
   
}
}

then to pan the zoomed in image you could use the use a Translate transform, add it to the same transform group some additional events and hey presto

Matias

unread,
Aug 5, 2013, 11:29:15 PM8/5/13
to fo-d...@googlegroups.com
Thanks Mahesh!

I'm using Windows Form but I think I can adapt the code you entered. I'll give it a try and then post the final code if I can make it work.

Thank you again.

Prashant Sharma

unread,
Aug 7, 2013, 2:06:15 AM8/7/13
to fo-d...@googlegroups.com
Hi Chris,
Please post the windows form code.

thanks.

Chris Horn

unread,
Aug 7, 2013, 3:15:28 AM8/7/13
to fo-d...@googlegroups.com
sorry I don't have the winforms version, I have a wfp guy for a number of years and don't use form unless I have to.

Prashant Sharma

unread,
Aug 14, 2013, 1:03:28 AM8/14/13
to fo-d...@googlegroups.com
Hi Matias
can you please post the zoom code for windows form.

Matias

unread,
Aug 17, 2013, 11:13:59 AM8/17/13
to fo-d...@googlegroups.com
Hi,

I haven't been able to figure out yet..

regards

Matias

unread,
Aug 18, 2013, 7:29:45 PM8/18/13
to fo-d...@googlegroups.com
I figured:
I have a picturebox inside a panel.

First, add this:

  panelmultipleimagenes.MouseEnter += new EventHandler(picbox_mpr_MouseEnter); // this is my panel
                picbox_mpr.MouseEnter += new EventHandler(picbox_mpr_MouseEnter); // mouse enter even for the picturebox
                panelmultipleimagenes.MouseWheel += new MouseEventHandler(picbox_mpr_MouseWheel); // mouse wheel event for panel

Then here are the functions:

 private void picbox_mpr_MouseWheel(object sender, MouseEventArgs e)
      {
          if (e.Delta < 0)
          {
              ZoomIn();
          }
          else
          {
           ZoomOut();
          }
      }

   private void picbox_mpr_MouseEnter(object sender, EventArgs e)
      {
          if (picbox_mpr.Focused == false)
          {
              picbox_mpr.Focus();
          }
      }

This is the function to zoom in:

  private void ZoomIn()
      {
          if ((picbox_mpr.Width < (MINMAX * panelmultipleimagenes.Width)) &&
              (picbox_mpr.Height < (MINMAX * panelmultipleimagenes.Height)))
          {
              picbox_mpr.Width = Convert.ToInt32(picbox_mpr.Width * ZOOMFACTOR);
              picbox_mpr.Height = Convert.ToInt32(picbox_mpr.Height * ZOOMFACTOR);
              picbox_mpr.SizeMode = PictureBoxSizeMode.StretchImage;
              img[0].Scale = img[0].Scale * ZOOMFACTOR;
              Image tmp = (Image)img[0].RenderImage(0);
              var image = new Bitmap(tmp);
              picbox_mpr.Image = image;
              tmp.Dispose();
          }
      }

and the function to zoom out:

  private void ZoomOut()
      {
          if ((picbox_mpr.Width > (panelmultipleimagenes.Width / MINMAX)) &&
              (picbox_mpr.Height > (panelmultipleimagenes.Height / MINMAX)))
          {
              picbox_mpr.SizeMode = PictureBoxSizeMode.StretchImage;
              picbox_mpr.Width = Convert.ToInt32(picbox_mpr.Width / ZOOMFACTOR);
              picbox_mpr.Height = Convert.ToInt32(picbox_mpr.Height / ZOOMFACTOR);
             
          }
      }

Matias

unread,
Aug 18, 2013, 7:41:04 PM8/18/13
to fo-d...@googlegroups.com
Forgot to mention these variables need to be added:

  private double ZOOMFACTOR = 1.25;
        private int MINMAX = 5;

Matias

unread,
Aug 18, 2013, 9:40:54 PM8/18/13
to fo-d...@googlegroups.com
I've even added some code to pan the image as it gets bigger..

Remember I have a picturebox inside a panel.

       private Point m_PanStartPoint;

Then:

     void picbox_mpr_MouseDown(object sender, MouseEventArgs e)
      {
          m_PanStartPoint = new Point(e.X, e.Y);
      }

and..


      void picbox_mpr_MouseMove(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Left)
          {
              int DeltaX = m_PanStartPoint.X - e.X;
              int DeltaY = m_PanStartPoint.Y - e.Y;
              panel.AutoScrollPosition = new Point((DeltaX - panel.AutoScrollPosition.X), (DeltaY - panel.AutoScrollPosition.Y));
          }

      }
Reply all
Reply to author
Forward
0 new messages