Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-19767

iOS: toImage does not honor the scale factor for retina devices

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: Release 4.0.0, Release 5.1.0, Release 5.0.0
    • Fix Version/s: Release 5.2.0
    • Component/s: iOS
    • Story Points:
      3
    • Sprint:
      2015 Sprint 25 SDK

      Description

      We used to have a honorScaleFactor property, that was removed as part of the 4.0.0.GA release in this PR around changes with non-attached images. The docs 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

        1. Actual.png
          Actual.png
          60 kB
        2. Expected.png
          Expected.png
          62 kB
        3. test.jpg
          test.jpg
          18 kB

          Issue Links

            Activity

              People

              • Assignee:
                hknoechel Hans Knöchel
                Reporter:
                hknoechel Hans Knöchel
                Reviewer:
                Chee Kiat Ng (Inactive)
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • It looks like Backbone Issue Sync is not enabled for your project.

                    Git Source Code