/// <summary> /// Adjust the size of the image according to the coerced scale factor. Optionally /// center the image, otherwise, try to keep the original midpoint of the pinch /// in the same spot on the screen regardless of the scale. /// </summary> /// <param name="center"></param> void ResizeImage(bool center) { if (_coercedScale != 0 && _bitmap != null) { double newWidth = canvas.Width = Math.Round(_bitmap.PixelWidth * _coercedScale); double newHeight = canvas.Height = Math.Round(_bitmap.PixelHeight * _coercedScale); xform.ScaleX = xform.ScaleY = _coercedScale; ImageViewPort.Bounds = new Rect(0, 0, newWidth, newHeight); if (center) { ImageViewPort.SetViewportOrigin( new Point( Math.Round((newWidth - ImageViewPort.ActualWidth) / 2), Math.Round((newHeight - ImageViewPort.ActualHeight) / 2) )); } else { Point newImgMid = new Point(newWidth * _relativeMidpoint.X, newHeight * _relativeMidpoint.Y); Point origin = new Point(newImgMid.X - _screenMidpoint.X, newImgMid.Y - _screenMidpoint.Y); ImageViewPort.SetViewportOrigin(origin); } } }
private void CreateViewport() { viewPort = new ImageViewPort(); toolControl.AddToolButton(Resources.send_bug, "Submit!").Click += submit_Click; toolControl.AddVerticalSeparator(); var selectTool = toolControl.AddToolButton(Resources.select_tool, "Selection Tool"); selectTool.Click += selectionTool_Click; selectTool.Togle = true; toolControl.AddToolButton(Resources.line_tool, "Line Tool").Click += lineTool_Click; toolControl.AddToolButton(Resources.square_tool, "Box Tool").Click += boxTool_Click; toolControl.AddToolButton(Resources.free_line_tool, "Free Line Tool").Click += freeLoneTool_Click; toolControl.AddToolButton(Resources.text_tool, "Text Tool").Click += textTool_Click; toolControl.AddVerticalSeparator(); toolControl.AddToolButton(Resources.undo, "Undo").Click += undo_Click; toolControl.AddToolButton(Resources.redo, "Redo").Click += redo_Click; toolControl.AddToolButton(Resources.delete, "Delete").Click += delete_Click; toolControl.AddVerticalSeparator(); toolControl.AddToolButton(Resources.plus, "Zoom In").Click += zoomIn_Click; toolControl.AddToolButton(Resources.minus, "Zoom Out").Click += zoomOut_Click; toolControl.AddToolButton(Resources.original_size, "Normal").Click += normalSize_Click; toolControl.AddVerticalSeparator(); toolControl.AddToolButton(Resources.save, "Save to File").Click += saveButton_Click; toolControl.AddToolButton(Resources.save, "Open").Click += open_Click; toolControl.AddVerticalSeparator(); toolControl.AddToolButton(Resources.new_capture, "Capture another Screen").Click += captureAnotherScreen_Click; Resizeble = true; viewPort.Size = new Size(100, 100); viewPort.Location = new Point(1, 70); toolControl.Location = new Point(1, 32); }