Cropping when moving and resizing a cropping rectangle

I created a program that crops an image and displays the cropped image but I'm trying to add more functionality
by making it movable and resizable. The rectangle moves and resizes but it only crops an image when user draws the rectangle and not when moved or resized. I know that the X,Y, height and width position of the rectangle would need to be updated but I'm not
sure how I can accomplish this being new to WPF. Below is my user control "CropControl and the code behind. Also, I'm implementing my code using MVVM framework.
XAML: 
<UserControl x:Class="Klein_Tools_Profile_Pic_Generator.CropControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="clr-namespace:Klein_Tools_Profile_Pic_Generator"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
<Rectangle Fill="Transparent"/>
</ControlTemplate>
<!-- ResizeDecorator Template -->
<ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
<Grid>
<s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 -4 0 0"
VerticalAlignment="Top"/>
<s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="-4 0 0 0"
VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
<s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="0 0 -4 0"
VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
<s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 0 0 -4"
VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
<s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE"
VerticalAlignment="Top" HorizontalAlignment="Left"/>
<s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW"
VerticalAlignment="Top" HorizontalAlignment="Right"/>
<s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW"
VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
<s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE"
VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</ControlTemplate>
<!-- Designer Item Template-->
<ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
<Control Template="{StaticResource ResizeDecoratorTemplate}"/>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Canvas x:Name="BackPanel"
MouseLeftButtonDown="LoadedImage_MouseLeftButtonDown"
MouseMove="LoadedImage_MouseMove"
MouseLeftButtonUp="LoadedImage_MouseLeftButtonUp"
Background="Transparent">
<ContentControl x:Name="contControl" Visibility="Collapsed"
Template="{StaticResource DesignerItemTemplate}">
<Rectangle x:Name="selectionRectangle" Fill="#220000FF"
IsHitTestVisible="False"/>
</ContentControl>
</Canvas>
</UserControl>
CODE BEHIND:
namespace Klein_Tools_Profile_Pic_Generator
/// <summary>
/// Interaction logic for CropControl.xaml
/// </summary>
public partial class CropControl : UserControl
private bool isDragging = false;
private Point anchorPoint = new Point();
private bool moveRect;
TranslateTransform trans = null;
Point originalMousePosition;
public CropControl()
InitializeComponent();
//Register the Dependency Property
public static readonly DependencyProperty SelectionProperty =
DependencyProperty.Register("Selection", typeof(Rect), typeof(CropControl), new PropertyMetadata(default(Rect)));
public Rect Selection
get { return (Rect)GetValue(SelectionProperty); }
set { SetValue(SelectionProperty, value); }
// this is used, to react on changes from ViewModel. If you assign a
// new Rect in your ViewModel you will have to redraw your Rect here
private static void OnSelectionChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e)
Rect newRect = (Rect)e.NewValue;
Rectangle selectionRectangle = d as Rectangle;
if (selectionRectangle != null)
return;
selectionRectangle.SetValue(Canvas.LeftProperty, newRect.X);
selectionRectangle.SetValue(Canvas.TopProperty, newRect.Y);
selectionRectangle.Width = newRect.Width;
selectionRectangle.Height = newRect.Height;
private void LoadedImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
if (isDragging == false)
anchorPoint.X = e.GetPosition(BackPanel).X;
anchorPoint.Y = e.GetPosition(BackPanel).Y;
Canvas.SetZIndex(selectionRectangle, 999);
isDragging = true;
BackPanel.Cursor = Cursors.Cross;
private void LoadedImage_MouseMove(object sender, MouseEventArgs e)
if (isDragging)
double x = e.GetPosition(BackPanel).X;
double y = e.GetPosition(BackPanel).Y;
contControl.SetValue(Canvas.LeftProperty, Math.Min(x, anchorPoint.X));
contControl.SetValue(Canvas.TopProperty, Math.Min(y, anchorPoint.Y));
contControl.Width = Math.Abs(x - anchorPoint.X);
contControl.Height = Math.Abs(y - anchorPoint.Y);
if (contControl.Visibility != Visibility.Visible)
contControl.Visibility = Visibility.Visible;
private void Image_MouseMove(object sender, MouseEventArgs e)
if (moveRect)
trans = selectionRectangle.RenderTransform as TranslateTransform;
if (trans == null)
selectionRectangle.RenderTransformOrigin = new Point(0, 0);
trans = new TranslateTransform();
selectionRectangle.RenderTransform = trans;
trans.Y = -(originalMousePosition.Y - e.GetPosition(BackPanel).Y);
trans.X = -(originalMousePosition.X - e.GetPosition(BackPanel).X);
e.Handled = false;
private void LoadedImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
if (isDragging)
isDragging = false;
if (contControl.Width > 0)
//Crop.IsEnabled = true;
//Cut.IsEnabled = true;
BackPanel.Cursor = Cursors.Arrow;
contControl.GetValue(Canvas.LeftProperty);
// Set the Selection to the new rect, when the mouse button has been released
Selection = new Rect(
(double)contControl.GetValue(Canvas.LeftProperty),
(double)contControl.GetValue(Canvas.TopProperty),
contControl.Width,
contControl.Height);

Hello HotSawz,
The ResizeThumb and MoveThumb is not in your code so I cannot compile. Anyway, it is not the problem.
Anyway, can you clarify more details about "it only crops an image when user draws the rectangle and not when moved or resized", it is already normal behavoir for you to draw a rectangle and then move it. What kind of action do you want? Do you
mean some controls like this:
http://www.codeproject.com/Articles/23158/A-Photoshop-like-Cropping-Adorner-for-WPF
Best regards,
Barry
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Moving and Resizing UIComponents

    Hi,
    I am making a flex application in which I am drawing Square,
    Rectangle,Ellipse, line,etc with flex UIComponent.
    I want to Moving and Resize the UIComponents .
    And what would be a better way to put UIComponent on some
    container and resize and move the container ? Or directly move and
    resize the UIComponent ?
    Can any one help me ??

    Hello all,
    regarding what I asked about, I've found this https://help.ubuntu.com/community/Resiz … Partitions
    So the question now is about moving. If I dd sda5 to sda4 will I have to set something up for it work? Like some offsets/adresses?
    If I am able to move sda5 to sda4, the rest will be fairly easy. Any about my partitiong layout - it's manual, I've used fdisk, cryptsetup, mkfs and the lvm tools that come with the arch install iso.
    Also some have misunderstood - currently everything but the boot partition, which is on another drive, is encrypted - in one LUKS partition and inside it there is an LVM with the different partitions.
    I've tested on a virtual machine by doing the following:
    unmount partitions
    move the luks partition by using dd with opts bs=4096 conv=notrunc,noerror,sync
    after that follow https://help.ubuntu.com/community/Resiz … Partitions
    Worked like a charm(if you need to remove mappers use dmsetup).
    After that: the uuid's of the lvm's are the same so that's cool. Just need to get the UUID of the new luks partition and set it in grub's cryptroot parameter.
    That's all
    Still I think I will backup everything first, then I will try this.
    Last edited by rand_x0r (2014-04-23 22:20:00)

  • After moving and resizing control, some controls don't redraw properly as the cursor passes over them.

    I have a top-level VI with three panes (two splitters).  One of the panes contains nested tab controls.  One of the tab pages contains six XY-graphs, a table and some decorations.
    I use a subVI to resize and relocate the tabs and contained controls.  All this is working fine, and everything looks fine after the resizing is complete.
    The problem is when the cursor passes over certain controls (the chart legends and the table column headers for example), they redraw with gray boxes.  The problem only occurs after enlarging the window from its minimum size.  It goes away if the window is resized back down to minimum.
    Anything that causes the window to redraw, like another resize or minimize/restore, properly refreshes the screen.
    Has anyone seen this problem, and have a workaround?
    The problem exists in development environment or built in LV 9.01 or LV 2010.
    Thanks!
    Matt Dennie
    Attachments:
    Resize Redraw Problem.zip ‏125 KB
    Resize Redraw Problem.JPG ‏210 KB

    Thanks again for taking a look at my problem.
    force redraw - This is apparently only available in LV2010.  I did give at a try, but it did not prevent the problem, nor did it correct the problem once the gray boxes appeared.
    disable updates (on a graph) - This apparently only applies to 3-D graphs, which is not what I am using in this case.
    disable front panel updates - I tried disabling updates before moving/resizing the front panel controls, then re-enabling updates afterwards.  The problem is exactly the same as before.  Once the move/resize is complete, passing the mouse over the table column headers or the graph plot legend results in the gray boxes.
    I would appreciate any other suggestions you may have. 
    Again... the problem is not that the moving and resizing don't work.  They work fine.  But once the resizing is complete, passing the mouse over the legend or table column headers causes gray boxes to appear.
    Thanks!
    -- Matt

  • Photoshop CS6 a little 'jerky' when moving layers & resizing window (Macbook Pro Retina 650m)

    As title says, when I open Photoshop CS6 and simple make a new layer and either use the type tool, it appears to be a little Sluggish/Jerky when moving the layer around.. The same applies when resizing photoshop itself.
    I'm updated to the latest version of CS6 and have tried all the combinations in the 'Performance' section of Photoshop.
    My Macbook Pro Retina is the 3.4ghz 650m and 8GB RAM offering (OS Mavericks). It's really annoying me as even my old laptop could run it smoothly and that was an i5 and much lower-end graphics card.
    The only way I can really describe it (and i'm no tech professional) is when comparing it to silky smooth 60 fps, it looks like it's skipping frames and in term looking 'jerky'. I also use Illustrator and don't really witness the same problem with it.
    I know this may have been asked quite a bit.. But I've never found the solution.. Could anybody advise me on what it potentially could be down too? (Might I add the laptop has just had a fresh install of the OS and a fresh copy of CS6)

    You could check through the GPU FAQ for anything you might have missed
    http://helpx.adobe.com/photoshop/kb/photoshop-cs6-gpu-faq.html
    You say you have tried all settings in Performance, but I wonder what your  cache levels are set at?  If more than 1, then OK.
    There's the general performance FAQ (no doubt lots of overlap)
    http://helpx.adobe.com/photoshop/kb/optimize-performance-photoshop-cs4-cs5.html
    Is this with all image docs, or particular ones?  For instance I have been playing with using ACR to process 32bit HDR files, and it puts a huge load on the system.

  • Moving and Resizing Panels

    I have some panels that I would like to allow the end-user to
    rearrange and resize to their liking.
    How would I go about doing this?

    I have some panels that I would like to allow the end-user to
    rearrange and resize to their liking.
    How would I go about doing this?

  • Moving and resizing shapes .?!

    hey there ..
    i was wondering if you guys can help me figure out how to select , move and resize a specific shape .... apreciatte it a lot .. peace . take care and thanks for your concerns..

    Hi there, take a look at this code:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=427823
    You can view the working version at www.bhun.net/shapebean.html. The example isn't very complicated nor does it contain much functionality. But it does show you one way to handle the shapes (there are probably better ones). Resizing a shape just requires you to do some extra work.
    Greets
    nuhb

  • Application windows remembering original anchor points when moving or resizing

    Recently it seems that most of my windows, especially iTunes, Safari, and Finder, seem to retain the anchor points from when they were opened and revert to their original position if a window is resized. I've noticed the following odd behaviors that seem to be related to this problem:
    After moving an iTunes or Safari window, right-clicking will open the context menu in a location that corresponds to where the window was originally placed.
    After moving a window, a drag-n-drop target remains relative to where the window was. For example, in iTunes, if I open the application and move the window, it becomes impossible to drag a song into a playlist (unless I drag the song to the location where that playlist was when the window originally opened). The same sort of thing happens with Finder windows. In the image below, a screen grab of a Safari window, I right-clicked on the signal strength display pictured on the phone to the left; notice the context menu way off to the right of the Safari window.
    Resizing a Safari window makes the window first snap back to the original location, then allows the resize to occur.
    Opening/closing a tab in Safari, when the action causes the tab bar to appear or disappear, causes the Safari window to snap back to the original anchored position.
    I've noticed this behavior over the past week or so. It was about a week ago that I installed the 10.9.5 update to the OS, but I'm not sure if the problem pre-dated the update or not.
    This is driving me insane. Does anyone have any suggestions or, hopefully, a fix?
    Thanks.

    You can try running the combo update.
    10.9.5 Combo Update

  • Acrobat 9 Pro hangs when moving or resizing stamps

    I've had this issue on two different machines running Windows 32 and 64 bit OS.
    Document opens fine and you can scroll around and perform operations. Until you put a stamp on it. Everything slows way down but doesn't quite stop. You can't resize or move the stamp although the cursor will eventually show the move or resize symbols because the entire program goes into a semi-freeze. You can't even close the window without waiting several minutes to regain "focus".
    If you shut it down and re-open all is normal...until you highlight or focus on the stamp, then the whole freeze or slowdown begins again,
    Anyone ever seen this? I can't find anything on it anywhere.

    Hi buybeach,
    Please update Acrobat to v9.5.5 and check. Was it working fine for you before?
    You might also want to repair Acrobat and check.
    Regards,
    Rave

  • Moving and Resizing the cover picture

    I need to move the cover picture and possibly resize it to fit the opening in a cover I am trying to use. Is this possible in iPhoto?

    Dibgiman43:
    Are you referring the the picture on the cover of an iPhoto book?
    Do you Twango?

  • Moving and resizing fields

    Hello,
    1. I want to make a field just a little bit smaller but when I grab the grab bars and drag to make it smaller it redcues it too much. How do I drag it very, very small amounts? I have looked for help topics on this and there is nothing. I have tried holding down ctrl, alt, and shift when I drag but nothing does it.
    2. How do I get a field to just nudge a little with arrow keys?
    Thank you.

    I use the Layout pallet to position object quite a bit. How ever I do use the arrow keys to nudge objects around the page. You might check and make sure that Snap to grid is unchecked otherwise when you use the arrow keys to move objects they will move in the increment the grid is set to. To set the grid or define grid and ruler settings and guides go to Windows -> Drawing Aids. I think snap to grid is checked by default.

  • RMBP clicking sound when moved and running

    This macbook pro retina is a few weeks old and i have not experienced any problems so far until today. I noticed that when I move the macbook slightly when it is on soft surface it makes a sort of sound which at first I thought was the fan hitting something, a quick high pitch click. It is like the sound when you move a laptop when its spining a cd. Its almost like the sound a small bell makes. The noise only happens when its awake and open, if I close the screen I can't seem to hear it. The point when it makes the noise is when it moves slightly from being flat to the ground, thats why I can only hear it when its on my lap or on something the rocks. Also something i just realised is that it will not make the sound if I move it around when holding it while the it is running and open, this makes me think that it has something to do with it being pushed together from the bottom. It sounds as if it is coming from the air vents at the bottom of the screen which once again makes me think it has something to do with the fan. Could you reply on what you think I should do? Its a 15 inch screen by the way.
    Thanks

    Normally, a clicking sound would be an indication of a bad HD or if the Superdrive is trying to read a damage disc. Personally, since its a week-old computer, I'd take a one hour drive than taking the chance of the HD failing after the warranty expired. You can try calling Apple as well (1800APPL). You should still have FREE phone support.

  • Use of Java Swing +Applescript to move and resize Mac OS X windows using

    Here is an interesting use of Java on Mac OS X and Applescript to
    enable moving and resizing of windows using mouse and keyboard:
    [MoveResize tool|http://code.google.com/p/sandipchitalesmacosxstuff/#Move_and_resize_windows_on_Mac_OS_X]
    How it works:
    The implementation uses Applescript to get the front most window and
    it's bounds. It sends the bounds rectangle to a server implemented in
    Java over a socket connection. The Java server takes the screen shot
    of the full Desktop and uses it as the Image label (a JLabel with
    ImageIcon) as the content pane of an undecorated JFrame which has the
    same bounds as the Desktop. A JPanel with semitransparent background
    and a dark rounded rectangular border is given the same bounds that
    were received over the socket. This JPanel is added to the
    PALETTE_LAYER of the JFrame's layered pane - which makes it appear
    floating in front of the front window. A Mouse and a Key listener
    added to the JPanel allow moving and resizing of the JPanel. When the
    user types the ENTER key the JFrame is hidden and the new bounds of
    the JPanel are sent back to the Applescript over the socket connection
    which moves and resizes the front most window.
    Enjoy!
    Sandip
    Edited by: chitale on May 14, 2009 4:12 AM

    Copy the /Home/Documents/ folder to the NAS drive. That drive needs to support AFP or you may run into filename problems and/or other file related problems due to filesystem differences.
    Once the folder has been moved to the NAS select the folder on the NAS and CTRL- or RIGHT-click. Select Make Alias from the drop down menu. You should now have an alias named "Documents alias." On the Mac put the /Home/Documents/ folder in the Trash but don't delete it. Copy the alias file from the NAS to the /Home/ folder. Rename it to simply "Documents." Double-click on it to be sure it opens the folder on the NAS. If so you can empty the Trash. You're done.

  • Adobe Air is very smiller than Zinc App - Reposition and Resize not working?

    Hello guys, i have found and readden nice solution like NativeWindow was saved positions and sizes If i close Adobe Air App and i open again like NativeWindow was moved and resized. It is very simple working. And it works fine. 100 % Good! But how does it work with Zinc App because it doesn't work for positions and sizes. How do i fix? I have upgraded code from FileSerializer.as With mdm.Script:
    package
      import flash.events.Event;
      import flash.net.URLRequest;
      import flash.net.URLStream;
      import flash.utils.ByteArray;
      import mdm.Application;
      import mdm.FileSystem;
      import mdm.System;
      public class FileSerializer
      public static function WriteObjectToFile(object:Object, filename:String):void
      var fileExists:Boolean = mdm.FileSystem.fileExists(mdm.Application.path+filename);
      var outByte:ByteArray = new ByteArray();
      outByte.writeObject(object);
      if(fileExists == false)
      mdm.FileSystem.saveFile(mdm.Application.path+filename, "");
      mdm.FileSystem.BinaryFile.setDataBA(outByte);
      mdm.FileSystem.BinaryFile.writeDataBA(mdm.Application.path+filename);
      private static var stream:URLStream;
      public static function ReadObjectfromFile(filename:String):Object
      var fileExists:Boolean = mdm.FileSystem.fileExists(mdm.Application.path+filename);
      if(fileExists == false)
      var obj:Object;
      stream = new URLStream();
      stream.addEventListener(Event.COMPLETE, function(evt:Event):void
      obj = stream.readObject();
      stream.close();
      stream.load(new URLRequest(filename));
      return obj;
      return null;
    That is improved to mdm.Script and it saves sometimes.
    And i have create UserPref.as
    package
      public class UserPref
      public var zincForm:String = "MainForm";
      public var zincType:String = "sizeablestandard";
      //public var zincSWF:String = "MainApp.swf";
      public var zincPosX:Number;
      public var zincPosY:Number;
      public var zincWidth:Number;
      public var zincHeight:Number;
    And i create MainApp.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      layout="absolute" applicationComplete="applicationCompleteHandler(event)" creatingComplete="creationCompleteHandler(event)">
      <fx:Script>
      <![CDATA[
      import mdm.Application;
      import mdm.Event;
      import mdm.Forms;
      import mdm.mdmForm;
      import mx.events.FlexEvent;
      private var up:UserPref;
      private var form:mdmForm;
      protected function applicationCompleteHandler(event:FlexEvent):void
      mdm.Application.init();
      this.up.zincPosX = this.form.x;
      this.up.zincPosY = this.form.y;
      this.up.zincWidth = this.form.width;
      this.up.zincHeight = this.form.height;
      FileSerializer.WriteObjectToFile(this.up, "pref.zup");
      mdm.Application.onAppExit = function (appevt:flash.events.Event):void
      mdm.Application.exit();
      mdm.Application.enableExitHandler();
      protected function creationCompleteHandler(event:flash.events.Event):void
      this.up = FileSerializer.ReadObjectfromFile("pref.zup") as UserPref;
      if(up) {
      mdm.Application.onFormReposition = function(rpevt:mdm.Event):void
      this.form.x = up.zincPosX;
      this.form.y = up.zincPosY;
      mdm.Application.onFormResize = function(rsevt:mdm.Event):void
      this.form.width = up.zincWidth;
      this.form.height = up.zincHeight;
      }else
      this.up = new UserPref();
      ]]>
      </fx:Script>
      <fx:Declarations>
      <!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
      </fx:Declarations>
    </mx:Application>
    And i recompile with Zinc Studio 4.0.22 than i try reposition and resize with Zinc Window than i close since saved files and i open again. But why does it not reposition and resize?
    How do i fix? Can somebody help me?
    Thanks best regards Jens Eckervogt

    I little more searching and I found the answer. Check it out here:
    http://forums.adobe.com/message/2879260#2879260

  • Can Effects etc. windows be moved or resized?

    The effects window is a little small and claustrophobic even on my 24" display.
    Can it be moved and resized?
    Also is there any PDF version of the Help Manual available?

    I have discovered how to download a PDF Help Manual:-
    1. Go here  http://help.apple.com/finalcutpro/mac/10.0/
    2. Click on the printer icon in the top right corner and select "Book".
    3. In the printer window click the "PDF" button and select "Save as PDF".
    I would still like to know about repositioning and resizing windows.

  • Mi swf (created on Catalyst) is cropped when I resize it on Modzilla and Explorer

    I made a Flash Catalyst file, and then exported it into an SWF File. When I open the HTML file with the swf, I try resizing or scaling the file and its gets cropped and is not in proportion with the window. Here you can see my file: www.estaydesigned.cl. Please!!! I need help

    In Flash Catalyst 1.0, the swf will not resize. To add this functionality you will have to manually add it within Flash Builder. This can be a complex process. In Flash Catalyst 5.5, resizable applications are now supported. FC 5.5 is slated to ship in May 2011. Don't know if that helps are not.
    Chris

Maybe you are looking for