【发布时间】: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