One of the hardest things to explain to new AppStudio users has always been “Why is it so hard to show an image in a PictureBox?”
PictureBox is based in the HTML5 Canvas element. To display an image on it, you used to need the following code:
'Pre AppStudio 4.0 code pb = PictureBox1.getContext("2d") myImage=new Image() Sub Main myImage.src="mario.jpg" End Sub Function myImage_onload() pb.drawImage(myImage,0,0) End Function
Since an image can take some time to load, it is done asynchronously. When the load is complete, unload is called to finish the display.
In AppStudio 4.0, it’s much simpler, using the new addImage() function:
'AppStudio 4.0 pb = PictureBox1.getContext("2d") pb.addImage("mario.jpg")
The addImage() function supports the same parameters as drawImage, so it is a straight replacement. It doesn’t need an Image object to initialize it, nor does it need an unload event when the load is finished. All that work is done automatically for you.