Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Can I insert a button in an image at specified location? I have tried but it shows Button is not a graphic function.

share|improve this question

3 Answers 3

up vote 12 down vote accepted

Lets get an image:

img = ExampleData[{"TestImage", "Lena"}];

Overlay is pretty easy to use for location specification. In the case below I used scaled coordinates:

Overlay[{img, Button[Style["Image Histogram", Blue, Italic, 34], 
   CreateDialog[ImageHistogram[img]]]}, All, 2, Alignment -> {.7, -.8}]

enter image description here

Here is a simple line to understand better how to place the button in different locations:

Overlay[{img, Button[Style["Image Histogram", Blue, Italic, 8], 
     CreateDialog[ImageHistogram[img]]]}, All, 2, Alignment -> #] & /@Tuples[{.7,-.7}, 2]

enter image description here

share|improve this answer

or maybe you don't want to put it on the image, but somewhere near it use this :

Column[
{Button["Transform", CreateDialog[ImageHistogram[img]]], Show[
img]]

Which works exactly the same but looks a little different.

share|improve this answer

You can use an inset:

Graphics[{Inset[
   RandomImage[CauchyDistribution[0, .2], {100, 100}, 
    ColorSpace -> "RGB"], Center], 
  Inset[Button["Click Here", Print[10!]], {Center, -0.5}]}, 
 Frame -> True]
share|improve this answer

Your Answer

 
discard

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.