![]() ![]() Js.Append "var img = canvas.toDataURL(""image/png base64 "") " // We access to the image data, encoded as a base64 string Js.Append "var canvas = document.getElementById('" + cCanvas.ControlID + "_canvas') " // We get the item reference based on its ID Once the WebButton has been added to the WebPage from the Library, put the following code in its Action Event Handler: Dim js() As String In fact, this will be the button in charge of calling the process to save the image as a picture file on the user disk. This is the process we will execute from the Action Event Handler of a WebButton added to the Web from the Library. The first interesting step is retrieving the underlying image represented by the WebCanvas and that is something we can get using a fragment of JavaScript code executed from the Xojo side. For example, we can draw a picture added to our project (with the filename “landscape”), using this line of code in the Paint event of our cCanvas instance: g.DrawPicture landscape, 0, 0, g.Width, g.Height Retrieving the WebCanvas image data Obviously, you can draw anything you want in the WebCanvas or even paint a picture on it. Use the following code to draw a black colored rectangle: g.FillRect 0, 0, g.Width, g.Height With the WebCanvas selected in the Navigator, change its name to cCanvas using the Inspector and add the Paint Event Handler to it using the Insert > Event Handler option from the menu. In order to follow this tutorial, create a new Web project and add a new WebCanvas control from the Library to the default Web Page added to the project: Web. However, by using a little JavaScript you can easily add this capability to Xojo. Sometimes is can be useful to be able to save the graphics drawn in the WebCanvas to an image file, but unfortunately there is no built-in Xojo method to do this. It takes advantage of the HTML5 Canvas making it fast and powerful. To give you an idea of how it is to integrate check out this screenshot of the 'App.The WebCanvas control is used for drawing graphics in web apps. It demonstrates how to map the folders and the Xojo Web app presents links to test the functionality very quickly. The example project demonstrates two distinct static folders with a PDF, image, and text file. It is a drop in module that extends the 'App' object of your Xojo Web project making integrating it super simple. ![]() The code we are presenting on GitHub today allows you to easily map folders to the Xojo Web application to be served as static content. It would be great if you could simply write your static files to a sub-folder inside of your app directory and serve those files directly. The other obvious downside is you now need a secondary web server and domain/sub-domain to serve these files. So it requires extra configuration to get your Xojo standalone app to be able to write to a specific folder of another domain. The problem at ServerWarp is we isolate your apps and domain web servers from each other to protect from vulnerabilities and provide the most secure environment. What if you want to email your user a link to the download? You can only access files that way if you have an active Xojo Web session. Technically the "WebFile" class works for this purpose but the user and development experience is a bit subpar especially for mobile clients. In order to serve those PDF reports they have often relied on writing those PDF files to another directory of another domain or subdomain because Xojo Web could not natively serve those files. This is especially useful if you are running standalone or load balanced apps and do not want to depend on another web server.įor example at ServerWarp we host many load balanced applications for customers. Now available on GitHub is open sourced code to help you serve static files from your Xojo Web application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |