I want to load an image with javascript and then show it on a form.
I know how to load the image:
var image = plugins.images.getImage(“C:\asd\asd.png”);
But then I don’t know what element to put in the form to receive the image.
On the form there must be a placeholder or someting, what is the right type of the element knowing that the image is 800*600 and will be switched often?
You can place the image in a media field or onto a Label/Button. Try this:
var vFile = plugins.file.showFileOpenDialog();
var vImage = plugins.images.getImage(vFile);
var vHeight = 400;
var vWidth = 300;
var vScaled_image = image.resize(vWidth, vHeight);
image_1 = vScaled_image;
image_1 is a field in this case and I’ve hardcoded vHeight & vWidth to shrink your photos by 50% but these would normally be variables selected by the User.
You can’t pass a string as file reference to the image plugin. It needs to be a JSFile object.
The following code would work:
var f = plugins.file.convertToJSFile("C:\\asd\\asd.png")
globals.myBigImage = plugins.images.getImage(f);
As you can see I put the image into a global field. This field is of type Media.
Now you can put a label or a field (with DisplayType set to image_media) and use the global as dataprovider.
You can’t do this with javascript variables, you need to use Servoy globals.
You set the dataprovider property of the label or did you used a %%merge code%% in the text property? You should use the dataprovider property.
Also make sure the global is of type MEDIA.
I tested to code I posted and it works fine for me…I am on a Mac though but that shouldn’t make a difference.
Hmm…I see the same thing in 3.1. (Java version 1.5.0_06-64 (Mac OS X))
Originally I tested it in 2.2.7 which worked fine.
Seems it’s utterly broken/changed in 3.1.
Can you also check out the getMetaDataProperties function of the image plugin. It seems to return a [Ljava.lang.String;.
Apparently not something javaScript can handle.