MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: interactive dragrect over a raster image

  • To: mathgroup at
  • Subject: [mg89616] Re: [mg89609] interactive dragrect over a raster image
  • From: John Fultz <jfultz at>
  • Date: Sun, 15 Jun 2008 06:12:33 -0400 (EDT)
  • Reply-to: jfultz at

On Sat, 14 Jun 2008 05:32:00 -0400 (EDT), rych wrote:
> I would like to be able to drag a rectangle with mouse over a raster
> image plot and dynamically update another plot, a histogram, for
> example, for the corresponding region? Something like Slider2D on the
> background of the image? Or is it better to program it using NETLink,
> or something?
> Igor

Here's a little something I put together quickly which gives you an idea how to 
do this.  Execute the code, then drag out some rectangles on the resulting 

The key here is to use LocatorPane in combination with the second argument of 

DragRectangle[Null, endPt_] := {};
DragRectangle[startPt_, endPt_] := {FaceForm[Opacity[0]], 
   EdgeForm[Dashing[Small]], Rectangle[startPt, endPt]};

DynamicModule[{startPt = Null, endPt = {0, 0}, 
  rectangle = {{0, 0}, {0, 0}}},
   {(startPt = 
       endPt = #) &, (endPt = #) &, (rectangle = {startPt, endPt = #};
       startPt = Null) &}], Graphics[{
    Red, Dynamic[Rectangle @@ rectangle], 
    Dynamic[DragRectangle[startPt, endPt]]}, Axes -> True, 
   PlotRange -> {{-1, 1}, {-1, 1}}], Appearance -> None]]

John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

  • Prev by Date: Re: Making Transparent Legend Backgrounds
  • Next by Date: Re: fit plane to xz axis of data
  • Previous by thread: interactive dragrect over a raster image
  • Next by thread: Re: interactive dragrect over a raster image