2016-09-26 33 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