【问题标题】:Appcelerator - Android open image galleyAppcelerator - Android 打开图片库
【发布时间】:2012-05-11 13:20:39
【问题描述】:

打开图片库时,应用程序有时会崩溃,有时却不会。 它显示了一个 java 异常,但没有任何有意义的消息。

有人有想法吗?我也使用了意图,但无法让它发挥作用。

谢谢!

这是我的代码示例:

Here a sample of my code:
function openGallery() {
var popoverView;
var arrowDirection;

if(Titanium.Platform.osname == 'ipad') {
    // photogallery displays in a popover on the ipad and we
    // want to make it relative to our image with a left arrow
    arrowDirection = Ti.UI.iPad.POPOVER_ARROW_DIRECTION_LEFT;
    popoverView = imageView;
}
var image = undefined;
Titanium.Media.openPhotoGallery({

    success : function(event) {
        var cropRect = event.cropRect;
        image = event.media;

        // set image view
        Ti.API.debug('Our type was: ' + event.mediaType);
        if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
            addAttachment(image);
        } else {
            // is this necessary?
        }
    },
    cancel : function() {

    },
    error : function(error) {
    },
    allowEditing : true,
    saveToPhotoGallery : true,
    popoverView : popoverView,
    arrowDirection : arrowDirection,
    mediaTypes : [Ti.Media.MEDIA_TYPE_VIDEO, Ti.Media.MEDIA_TYPE_PHOTO]
   });
}

【问题讨论】:

    标签: javascript android image titanium appcelerator


    【解决方案1】:
    var win = Titanium.UI.createWindow({
        title:"Accessing the photo album",
        backgroundColor:"#FFFFFF",
        exitOnClose:true
    });
    
    var button = Titanium.UI.createButton({
        title:"Open the photo gallery",
        width:180,
        height:48,
        bottom: 12,
        zIndex:2
    });
    
    button.addEventListener("click", function(e){
        //Open the photo gallery
        Titanium.Media.openPhotoGallery({
            //function to call upon successful load of the gallery
            success:function(e){
                //e.media represents the photo or video
                var imageView = Titanium.UI.createImageView({
                    image:e.media,
                    width:320,
                    height:480,
                    top:12,
                    zIndex:1
                });
    
                win.add(imageView);
            },
            error:function(e){
                alert("There was an error");
            },
            cancel:function(e){
                alert("The photo gallery was cancelled");
            },
            //Allow editing of media before success
            allowEditing:true,
            //Media types to allow
            mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
            //The other is Titanium.Media.MEDIA_TYPE_VIDEO
        });
    });
    
    win.add(button);
    
    win.open();
    

    【讨论】:

      【解决方案2】:

      当我从项目切换时,上述 cmets 从未解决过这个问题。

      【讨论】:

        猜你喜欢
        • 2014-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多