Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make a cookie cutter that will extract a small square from a much larger bitmap with a click of the mouse. The LocatorPane appears to be a useful way to move the cookie cutter around, but I'm not having much luck in drawing the small dynamic rectangle over the bitmap. I would like to change the appearance of the locator icon to a small rectangle, or just make the locator icon disappear. The LocatorPane option Appearance -> Graphics[Rectangle[]] didn't work. Beyond that there is the question of how to capture a point value with a mouse click. This is my first use of Dynamic. I suspect I am going about this all the wrong way and perhaps I should be doing something with mouse functions and cursor images. If so, I would appreciate it if someone would point me towards a pertinent page or two. I have not been able to find one.

This script draws the locator on a bitmap labeled "background":

background = Image[Graphics[{LightGray, Rectangle[]}]];
    {pt = {180, 180}},
     LocatorPane[Dynamic[pt], background]

But when I add code for the dynamic rectangle, I find that it draws outside the background bitmap.

{pt = {180, 180}},
  {LocatorPane[Dynamic[pt], background],


     {EdgeForm[{Thick, Red}],


share|improve this question
Related: Szabolcs applied the crop rectangle to zoom into graphics objects here. – István Zachar Oct 3 '12 at 22:49
Also see image cropper here. – István Zachar Oct 3 '12 at 23:05
up vote 6 down vote accepted

Combine the background and the Graphics with Show, so that you can supply both of them as the second argument to LocatorPane:

background = Image[Graphics[{LightGray, Rectangle[]}]];
DynamicModule[{pt1 = {180, 180}, pt2 = {20, 20}},
 LocatorPane[Dynamic[{pt1, pt2}],
   Graphics[{EdgeForm[{Thick, Red}],
     FaceForm[], Rectangle[Dynamic[pt1], Dynamic[pt2]]}]]
  , Appearance -> Graphics[Rectangle[], ImageSize -> {10, 10}]]]

enter image description here

Update After further clarification of the question:

background = Image[Graphics[{LightGray, Rectangle[]}]];
DynamicModule[{pt1 = {180, 170}, pt2 = {190, 180}}, 
   Graphics[{EdgeForm[{Thick, Red}], FaceForm[], 
     Dynamic[Rectangle[pt1 + {5, 5}, pt1 - {5, 5}]]}]], Appearance -> None]]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.