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