Problem Description
iOS and Android return different objects from the generic
"toImage()" function you can call on any view. iOS returns a blob,
but Android returns a dictionary (with width, height, x, y,
cropRect and media). So if you want to save the result to a file,
you need to have different code for the two platforms.
Solution
I don't presume to know the solution to this one, but if the
result could be coerced to a blob when it is used as one, that
would allow for the same code to work on both platforms. This seems
like a sticky situation because existing code will be broken on
either platform, depending on the route taken.
Sample Code
The following sample code works, but it requires conditional
code for the platform: ".write(Ti.Android ? image.media ?
image)".
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var web = Ti.UI.createWebView({
url: 'http://www.google.com/'
});
web.addEventListener('load', function() {
var image = web.toImage();
i.Filesystem
.getFile(Titanium.Filesystem.applicationDataDirectory, 'snapshot_blob.png')
.write(Ti.Android ? image.media : image);
alert('PASS: Image saved.');
});
win.add(web);
win.open();
Associated API Docs
The API Docs say toImage returns a blob.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.View.toImage-method.html
Tested On
Titanium SDK version: 1.7.0 (03/03/11 10:45 87a2113...)
iPhone Simulator 4.2
Android Emulator 2.2 APIs
Android Device Epic 4G 2.2
Associated Helpdesk Ticket
http://developer.appcelerator.com/helpdesk/view/76200
Any updates on this issue?
Tested on a Samsung Galaxy S2 and the iOS simulator using TiSDK 2.2.0v20120904101713, issue still valid.
Verified the issue is not reproducible. The view.toImage() successfully converts the webview to image in the above test code. Environment: Appc Studio : 3.2.1.201402061120 Ti SDK : 3.2.1.GA Mac OSX : 10.8.5 Alloy : 1.3.1 CLI - 3.2.1 Nexus 5 - android 4.4.2 Samsung S4 - android 4.2.2 Samsung S3 - android 4.0.4
I can reproduce this on 3.4.1.RC
Test Case
Android
iOS:
I have the same issue. I tried to use [http://www.batasoft.com/appcelerator/app-icons](http://www.batasoft.com/appcelerator/app-icons) and this lib uses toImage() to convert a label to a image for using in tabgroup.
This issue was fixed by https://github.com/appcelerator/titanium_mobile/pull/6907
Resolved as invalid.
Closing ticket as invalid with reference to the above comments.