2016-09-26 66 views
0

請幫助,我正在做一個縮略圖的相機拍攝的照片,並在base64編碼。原生腳本:黑色空間,而不是照片縮略圖

的Javascript:

class Entry { 

    get thumbnail() { 
     return (this._thumbnail || null); 
    } 

    set thumbnail(value) { 
     let scaledImage = false; 
     if (value) { 
      if (value.android) { 
       const aspectSafeSize = common.getAspectSafeDimensions(value.width, value.height, config.thumbWidth, config.thumbHeight); 
       scaledImage = android.graphics.Bitmap.createScaledBitmap(value.android, aspectSafeSize.width, aspectSafeSize.height, true); 
      } 
      if (value.ios) { 
       const cgSize = CGSizeMake(config.thumbWidth, config.thumbHeight); 
       UIGraphicsBeginImageContextWithOptions(cgSize, false, 0.0); 
       value.ios.drawInRect(CGRectMake(0, 0, config.thumbWidth, config.thumbHeight)); 
       scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 
       UIGraphicsEndImageContext(); 
      } 
     } 
     if (scaledImage) { 
      const scaledImageSource = new ImageSourceModule.ImageSource(); 
      scaledImageSource.setNativeSource(scaledImage); 
      const t = 'data:image/png;base64,' + scaledImageSource.toBase64String('png',100); 
      this._thumbnail = t; 
     } 
    } 
} 

在XML:

<Image top="0" left="0" src="{{ thumbnail }}" stretch="aspectFill" visibility="{{ thumbnail ? 'visible' : 'collapsed' }}"/> 

但只顯示黑色空間:screenshot。 此外,如果編碼的數據獲取和嘗試來解碼,我們得到了一個正常的圖像

+0

檢查你的css中的某處是否將css'color'設置爲黑色如果你在2.3.0上,因爲存在導致圖像從css獲取顏色作爲繼承的bug –

+0

非常感謝! – Zakus

回答

1

如果你的CSS屬性顏色設置任何父元素:在NativeScript 2.3.0 this is documented bug並定於固定與下一個版本(2.4.0)。如果您想使用下一個版本在這個非常時刻,你可以用這個步驟做:

tns plugin remove tns-core-modules 
tns plugin add [email protected] 

現在你將有其中已經應用了修復最新的模塊。

+0

非常感謝! – Zakus