【问题标题】:appcelerator titanium base64 encode blob objectsappcelerator 钛 base64 编码 blob 对象
【发布时间】:2011-09-23 11:56:28
【问题描述】:

我正在使用 appcelerator Titan (sdk 1.6.2) 开发移动 (iphone/android) 应用程序。 在应用程序的某个时刻,用户选择了应该在 imageView 中显示的图像,base64 编码,然后上传到我的服务器。 问题是照片库的成功事件将所选图像作为 blob 对象返回,并且 Titanium.Utils.base64encode 方法只接受字符串值! 有没有办法将 Titanium.Blob 对象转换为字符串?

这里是sn-p的代码:

var imageView = Titanium.UI.createImageView({
height:200,
width:200,
top:20,
left:10,
backgroundColor:'#999'
});

Titanium.Media.openPhotoGallery({

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

    // set image view
    Ti.API.debug('Our type was: '+event.mediaType);
    if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
    {
        imageView.image = image;// this works
        var imgStr=Ti.Utils.base64encode(image);// doesn't work because 'image' has to be a string!, but how?
    }
    else
    {

    }

    Titanium.API.info('PHOTO GALLERY SUCCESS cropRect.x ' + cropRect.x + ' cropRect.y ' + cropRect.y  + ' cropRect.height ' + cropRect.height + ' cropRect.width ' + cropRect.width);

},
allowEditing:true,
popoverView:popoverView,
arrowDirection:arrowDirection,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});

谢谢,

【问题讨论】:

    标签: base64 blob titanium appcelerator encode


    【解决方案1】:
    var imgStr=Ti.Utils.base64encode(image.toString());
    

    .toString() 将某些内容转换为字符串表示

    【讨论】:

      【解决方案2】:

      我刚刚发布了一些用于执行此转换的模块的代码,我知道来自 appcelerator 的补丁,但该模块现在可能对您有用。

      Clearly Innovative Thoughts - Titanium Appcelerator Quickie: base64encode iOS Module

      【讨论】:

        【解决方案3】:

        这对我有用。

        var image = event.media;
        var imgStr = Ti.Utils.base64encode(image).toString();
        

        【讨论】:

          猜你喜欢
          • 2015-03-17
          • 1970-01-01
          • 2013-11-23
          • 1970-01-01
          • 2014-08-01
          • 2016-11-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多