Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Upload image from send intent

$
0
0

I'm trying to cast upload on a blob I receive from a send intent. The intent more or less works, but I cannot get the image to an imageview, or to upload afterward. We have the following mishmash :

function resizePhoto(media, size) {
    var oW = media.width;
    var oH = media.height;
    var w = oW >= oH ? Math.round(Math.min(size, oW)) : Math.round(Math.min(oW * (size / oH), oW));
    var h = oW <= oH ? Math.round(Math.min(size, oH)) : Math.round(Math.min(oH * (size / oW), oH));
    return media.imageAsResized(w, h);
};
 
function photoDevelop() {
    photo.opacity = 0.01;
    photo.visible = true;
    photo.animate({
        opacity : 1,
        duration : 250
    });
    Ti.API.info('Image Width ' + photo.image.width + " & Height " + photo.image.height);
}
 
function getIntent() {
    var activity = Ti.Android.currentActivity;  // Tried getCurrentActivity() and app crashed citing "no such function."
    var intent = activity.getIntent();
    var extra = Ti.Android.EXTRA_STREAM;
    var blob = intent.getBlobExtra(extra); // le blob of info
    Ti.API.info("Intent?");
    Ti.API.info(intent.getAction());
    Ti.API.info(intent.getData());
    Ti.API.info(intent.getBlobExtra(extra));
    Ti.API.info(intent.getType());
    if (intent && intent.hasExtra(extra)) {
        if (blob.width < 4096 && blob.height < 4096) {
            var tmp = Ti.UI.createImageView({
                image : blob
            });
            var tmp2 = Ti.UI.createImageView({
                image : tmp.toImage(),
                height : blob.height,
                width : blob.width
            });
            tmp = null;
            blob = null;
            photo.image = resizePhoto(tmp2.toBlob(), 1024);
            tmp2 = null;
            photoDevelop();
        } else {
            Ti.UI.createAlertDialog({
                title : "It's too big.",
                buttonNames : ["I get that a lot."]
            }).show();
        }
    }
}
I've tried assigning the blob of data directly to an image view and get nothing. With openphotogallery, I have to assign the blob to a temporary imageview and then pass it to the resize function else it claims null pointer. In this case, after going toImage and then back toBlob, the final result is not null, but may as well be as it results in width : 1, height : 1.

In short, my question here is: How do I assign the intent blob to an imageview, and then pass it to my upload function?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>