Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25758] iOS: Image will be cut in the bottom after apply imageAsCompressed and imageAsSized

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionDuplicate
Resolution Date2018-02-07T08:46:32.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterShuo Liang
AssigneeEric Merriman
Created2018-02-07T07:26:43.000+0000
Updated2018-02-07T08:46:32.000+0000

Description

Reproduce

1.Add following simple code to classic app. 2.Run the app on iOS device. 3.Click button to pick one of your image, then display it. You will see the image is cut in the bottom.
var win = Ti.UI.createWindow({
    backgroundColor:"white"
});

var button = Ti.UI.createButton({
    title : 'Open Gallery',
    width : 100,
    height : 50,
    top : 20
});

var imageView = Ti.UI.createImageView({
    top : 100
});

button.addEventListener('click', function(){
    Ti.Media.openPhotoGallery({
        success: function(event) {
            Ti.API.debug(event.mediaType);
            if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
                
                var obj = calculateAspectRatioFit(event.media.width, event.media.height, 700, 700);
                var resizedBlob = event.media.imageAsResized(obj.width, obj.height);
                resizedBlob.imageAsCompressed(0.7);

                imageView.image = resizedBlob;
                win.add(imageView);
            }
        },
        cancel: function() {},
        error: function(e) {
            Ti.API.error(e.code);
        },
    });
});

win.add(button);
win.open()

function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {
    var ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight);

    return {
        width : srcWidth * ratio,
        height : srcHeight * ratio
    };
}

Note.

Seems only happened to iOS.

Attachments

FileDateSize
01517988429_original.png2018-02-07T08:08:10.000+00001146976
IMG_4269.png2018-02-07T08:07:57.000+00001180818

Comments

  1. Shuo Liang 2018-02-07

    Duplicate to TIMOB-25336

JSON Source