Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19767] iOS: toImage does not honor the scale factor for retina devices

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2015-11-26T08:54:54.000+0000
Affected Version/sRelease 4.0.0, Release 5.1.0, Release 5.0.0
Fix Version/sRelease 5.2.0
ComponentsiOS
Labelsios, retina, scale, toimage
ReporterHans Knöchel
AssigneeHans Knöchel
Created2015-10-22T18:10:55.000+0000
Updated2016-01-15T18:04:46.000+0000

Description

We used to have a honorScaleFactor property, that was removed as part of the 4.0.0.GA release in [this PR](https://github.com/appcelerator/titanium_mobile/pull/6302) around changes with non-attached images. The [docs](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-method-toImage) say, the property was already removed in 3.5.0, but worked until 3.5.1.GA. I would like to get this property back to achieve a proper behavior in the following use case. *Use case*: Use toImage() to make an image (blob) of a view, that covers a specified square inside another view. *Demo:*
var win1 = Titanium.UI.createWindow({
	backgroundColor : '#fff'
});

var imageView = Ti.UI.createImageView({
	image : "test.jpg"
});

imageView.addEventListener("click", imageViewClicked);

win1.add(imageView);
win1.open();

function imageViewClicked(e) {
	imageView.removeEventListener("click", imageViewClicked);

	var edgeLength = 100;
	var blob = imageView.toImage();

	var tempView = Ti.UI.createView({
		width : blob.width + edgeLength,
		height : blob.height + edgeLength
	});

	tempView.add(Ti.UI.createImageView({
		image : blob,
		width : blob.width,
		height : blob.height
	}));

    // No callback -> get blob directly, honorScaleFactor false -> Same size for retina and non-retina
    // Default functionality still the same: No callback and secons argument true / undefined -> Different size for retina and non-retina
	blob = tempView.toImage(null, false);

	var image = blob.imageAsCropped({
		width : edgeLength,
		height : edgeLength,
		x : e.x,
		y : e.y
	});

	var croppedImageView = Ti.UI.createImageView({
		image : image,
		bottom : 0,
		borderWidth : 1,
		borderColor : "black",
		borderRadius : edgeLength / 2
	});

	croppedImageView.addEventListener("click", function() {
		win1.remove(croppedImageView);
		imageView.addEventListener("click", imageViewClicked);
	});

	win1.add(croppedImageView);
}
*Expected behavior*: The method works same on retina and non-retina devices. *Actual behavior:* The method uses the wrong scale on creating the image blob. *Proposal*: Bring back the honorScaleFactor property, make the default value to true as the current behavior expects. That would achieve the configuration of the property, but would not break any existing applications.

Attachments

FileDateSize
Actual.png2015-10-22T18:30:00.000+000061508
Expected.png2015-10-22T18:30:00.000+000063258
test.jpg2015-10-22T18:27:29.000+000018647

Comments

  1. Angel Petkov 2015-11-24

    FT passed , PR approved. Thanks Hans!
  2. Josh Longton 2016-01-15

JSON Source