2011-06-27 60 views
2

我正在開發一個使用appcelerator鈦(sdk 1.6.2)的移動(iphone/android)應用程序。 在應用程序中的某個點,用戶選擇應該在imageView中顯示的圖像,base64編碼,然後上傳到我的服務器。 問題是照片庫的成功事件將所選圖像作爲斑點對象返回,並且Titanium.Utils.base64encode方法僅接受字符串值! 有沒有什麼辦法可以將Titanium.Blob對象轉換爲字符串?appcelerator鈦base64編碼blob對象

這裏是代碼片段:

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] 
}); 

謝謝

回答

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

的ToString()轉換的東西字符串表示

1

這對我有效。

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