{ "id": "63900", "key": "TIMOB-3268", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2016-09-28T12:08:52.000+0000", "created": "2011-04-15T03:40:51.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "api", "parity" ], "versions": [ { "id": "11244", "name": "Release 1.7.0", "archived": true, "released": true, "releaseDate": "2011-06-13" }, { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [], "assignee": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-24T17:58:25.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "h5. Problem Description \r\n\r\niOS and Android return different objects from the generic\r\n\"toImage()\" function you can call on any view. iOS returns a blob,\r\nbut Android returns a dictionary (with width, height, x, y,\r\ncropRect and media). So if you want to save the result to a file,\r\nyou need to have different code for the two platforms.

\r\n\r\nh5. Solution \r\nI don't presume to know the solution to this one, but if the\r\nresult could be coerced to a blob when it is used as one, that\r\nwould allow for the same code to work on both platforms. This seems\r\nlike a sticky situation because existing code will be broken on\r\neither platform, depending on the route taken.\r\nh5.Sample Code\r\nThe following sample code works, but it requires conditional\r\ncode for the platform: \".write(Ti.Android ? image.media ?\r\nimage)\".\r\n \r\n{code}\r\n\r\nvar win = Ti.UI.createWindow({ backgroundColor: '#fff' });\r\n\r\nvar web = Ti.UI.createWebView({\r\n url: 'http://www.google.com/'\r\n});\r\nweb.addEventListener('load', function() {\r\n var image = web.toImage();\r\n i.Filesystem\r\n .getFile(Titanium.Filesystem.applicationDataDirectory, 'snapshot_blob.png')\r\n .write(Ti.Android ? image.media : image);\r\n alert('PASS: Image saved.');\r\n});\r\nwin.add(web);\r\n\r\nwin.open();\r\n{code}\r\n \r\nh5.Associated API Docs \r\n The API Docs say toImage returns a blob. \r\n http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.View.toImage-method.html \r\n\r\nh5.Tested On \r\n Titanium SDK version: 1.7.0 (03/03/11 10:45 87a2113...) \r\niPhone Simulator 4.2 \r\nAndroid Emulator 2.2 APIs \r\nAndroid Device Epic 4G 2.2 \r\n\r\nh5.Associated Helpdesk Ticket \r\n http://developer.appcelerator.com/helpdesk/view/76200 ", "attachment": [], "flagged": false, "summary": "Android: View.toImage() Platform Inconsistency", "creator": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "environment": "Android 2.3.3\r\nMac OS X 10.8.5\r\nTi CLI 3.2.0 \r\nTi SDK 3.2.0.GA\r\n", "comment": { "comments": [ { "id": "180903", "author": { "name": "ssavic", "key": "ssavic", "displayName": "Sasa Savic", "active": true, "timeZone": "America/New_York" }, "body": "Any updates on this issue?", "updateAuthor": { "name": "ssavic", "key": "ssavic", "displayName": "Sasa Savic", "active": true, "timeZone": "America/New_York" }, "created": "2012-01-27T10:47:51.000+0000", "updated": "2012-01-27T10:47:51.000+0000" }, { "id": "217507", "author": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "body": "Tested on a Samsung Galaxy S2 and the iOS simulator using TiSDK 2.2.0v20120904101713, issue still valid. ", "updateAuthor": { "name": "jyounus", "key": "jyounus", "displayName": "Junaid Younus", "active": true, "timeZone": "Europe/London" }, "created": "2012-09-04T14:24:10.000+0000", "updated": "2012-09-04T14:24:10.000+0000" }, { "id": "295435", "author": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Verified the issue is not reproducible. The view.toImage() successfully converts the webview to image in the above test code.\n\nEnvironment:\nAppc Studio : 3.2.1.201402061120\nTi SDK : 3.2.1.GA\nMac OSX : 10.8.5\nAlloy : 1.3.1\t\nCLI - 3.2.1\nNexus 5 - android 4.4.2\nSamsung S4 - android 4.2.2\nSamsung S3 - android 4.0.4", "updateAuthor": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-03-04T01:01:19.000+0000", "updated": "2014-03-04T01:01:19.000+0000" }, { "id": "332175", "author": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "I can reproduce this on 3.4.1.RC\r\n\r\nh1. Test Case\r\n\r\n{code}\r\nvar b = Ti.UI.createView().toImage();\r\n\r\nconsole.log(typeof b);\r\nconsole.log(b.apiName);\r\nconsole.log(b);\r\n{code}\r\n\r\nh1. Android\r\n\r\n{code}\r\nobject\r\nundefined\r\n{\r\n \"cropRect\": {\r\n \"height\": 318,\r\n \"width\": 318,\r\n \"x\": 0\r\n },\r\n \"height\": 318,\r\n \"media\": {\r\n \"height\": 318,\r\n \"bubbleParent\": true,\r\n \"type\": 2,\r\n \"mimeType\": \"image/png\",\r\n \"apiName\": \"Ti.Blob\",\r\n \"nativePath\": null,\r\n \"file\": null,\r\n \"text\": null,\r\n \"length\": 29062,\r\n \"width\": 318\r\n },\r\n \"mimeType\": \"image/png\",\r\n \"y\": 0,\r\n \"width\": 318,\r\n \"x\": 0\r\n}\r\n{code}\r\n\r\nh1. iOS:\r\n\r\n{code}\r\nobject\r\nTi.Blob\r\n{}\r\n{code}", "updateAuthor": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2014-11-14T09:57:52.000+0000", "updated": "2014-11-14T09:57:52.000+0000" }, { "id": "360210", "author": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "body": "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.", "updateAuthor": { "name": "titanium@webmasterei-hamburg.de", "key": "titanium@webmasterei-hamburg.de", "displayName": "Rainer Schleevoigt", "active": true, "timeZone": "Europe/Berlin" }, "created": "2015-08-18T17:22:54.000+0000", "updated": "2015-08-18T17:22:54.000+0000" }, { "id": "397500", "author": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This issue was fixed by https://github.com/appcelerator/titanium_mobile/pull/6907\r\n\r\n{code}\r\nvar b = Ti.UI.createView().toImage();\r\nTi.API.info(typeof b);\r\nTi.API.info(b.apiName);\r\nTi.API.info(b);\r\n{code}\r\n{code}\r\nobject\r\nTi.Blob\r\n[object TiBlob]\r\n{code}\r\n\r\nResolved as invalid.", "updateAuthor": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2016-09-28T12:06:08.000+0000", "updated": "2016-09-28T12:08:16.000+0000" }, { "id": "415600", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as invalid with reference to the above comments.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-24T17:58:25.000+0000", "updated": "2017-03-24T17:58:25.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }