Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28246] Android: Ti.Media.previewImage() fails to display in-memory blobs as of 9.1.0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionUnresolved
Affected Version/sRelease 9.1.0
Fix Version/sRelease 9.3.0
ComponentsAndroid
Labelsandroid, blob, media, preview, regression
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-11-19T03:28:18.000+0000
Updated2020-11-20T23:36:23.000+0000

Description

*Summary:* The [Ti.Media.previewImage()](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-method-previewImage) method fails to display in-memory blobs (ie: blobs not referencing a file) as of Titanium 9.1.0. *Steps to reproduce:*

Build and run the below on Android.

Tap on the "Preview" button. (Will try to display screenshot of app.)

Notice it fails to display image.

var window = Ti.UI.createWindow();
var button = Ti.UI.createButton({ title: "Preview" });
button.addEventListener("click", function(e) {
	window.toImage(function(imageBlob) {
		if (!imageBlob) {
			return;
		}
		Ti.Media.previewImage({
			image: imageBlob,
			success: function(e) {
				Ti.API.info("@@@ Successfully displayed preview.");
			},
			error: function(e) {
				Ti.API.error("@@@ Failed to display preview");
			},
		});
	});
});
window.add(button);
window.open();
*Work-Around:* Save the blob to file and preview the file instead.
var window = Ti.UI.createWindow();
var button = Ti.UI.createButton({ title: "Preview" });
button.addEventListener("click", function(e) {
	window.toImage(function(imageBlob) {
		if (!imageBlob) {
			return;
		}

		// Write the blob to file.
		var targetFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "image.png");
		targetFile.write(imageBlob, false);
		imageBlob = targetFile.read();

		// Preview the above file.
		Ti.Media.previewImage({
			image: imageBlob,
			success: function(e) {
				Ti.API.info("@@@ Successfully displayed preview.");
			},
			error: function(e) {
				Ti.API.error("@@@ Failed to display preview");
			},
		});
	});
});
window.add(button);
window.open();

Comments

  1. Joshua Quick 2020-11-19

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12271
  2. Satyam Sekhri 2020-11-20

    FR Passed
  3. Christopher Williams 2020-11-20

    merged to master and 9_3_X for 9.3.0 target.
  4. Joshua Quick 2020-11-20

    Fixed minor regression within TiFileHelper class' deployFromAssets() and deployFromZip() methods. Note that nobody uses these methods. It is dead code... but "could" potentially be used in the future. PR (master): https://github.com/appcelerator/titanium_mobile/pull/12281

JSON Source