5
$\begingroup$

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

$\endgroup$
12
$\begingroup$

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

$\endgroup$
7
$\begingroup$

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]
$\endgroup$
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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