3
$\begingroup$

Hello I am a beginner in Mathematica and I have a question about initialization of manipulate. I have code like this and I want to ask you, how to modify that code if I want have default picture saved in variable "image", but only in first use of this manipulate.

 Manipulate[
    Column[{
    Button["LoadPicture", image=Import[SystemDialogInput["FileOpen"]],Method -> "Queued"],
    image    
    }],{input,"Enter your number","Number:"}
    ]

I tried some condition where I want save there empty string and after loaded picture show that picture...like this:

 Manipulate[
    Column[{
    Button["LoadPicture", image=Import[SystemDialogInput["FileOpen"]],Method -> "Queued"],
    If[ImageQ[image]==False, image=""];
    image    
    }],{input,"Enter your number","Number:"}
    ]

but there always kernel crashed.

$\endgroup$
  • $\begingroup$ ye I can add this, but it still does not fix my problem $\endgroup$ – Recktus Oct 6 '16 at 7:22
  • $\begingroup$ yes it still crashes $\endgroup$ – Recktus Oct 6 '16 at 7:34
  • $\begingroup$ Sorry, can't reproduce the problem. $\endgroup$ – Kuba Oct 6 '16 at 7:55
2
$\begingroup$
Manipulate[
 image,
 Button["LoadPicture", image = Import[SystemDialogInput["FileOpen"]], 
  Method -> "Queued"],
  {{ image, <<< PASTE the image here >>>> },None}
]

Here is how it looks like:

Mathematica graphics

i.e. first get the image you want as default,

Mathematica graphics

the copy-paste it directly inside Manipulate variable as above.

Here is a demo:

enter image description here

Manipulate[
 image,
 Button["LoadPicture", 
  image = Import[SystemDialogInput["FileOpen", def]], 
  Method -> "Queued"],
  {{image,<<< IMAGE HERE >>>},None},
  {{def, "C:\\Program Files\\Wolfram\\Research\\Mathematica\\11.0\\Documentation\\English\\System\\ExampleData\\*.tiff"}, None}

 ]
$\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.