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。 此外,如果编码的数据获取和尝试来解码,我们得到了一个正常的图像
检查你的css中的某处是否将css'color'设置为黑色如果你在2.3.0上,因为存在导致图像从css获取颜色作为继承的bug –
非常感谢! – Zakus