Use bitmap source width

This commit is contained in:
Katie Broida 2019-03-05 11:08:49 -05:00
parent 33f4482127
commit aeea9c1a51

View file

@ -850,10 +850,13 @@ class VirtualMachine extends EventEmitter {
costume.rotationCenterX = rotationCenterX;
costume.rotationCenterY = rotationCenterY;
// If the bitmap originally had a zero width or height, use that value
const bitmapWidth = bitmap.sourceWidth === 0 ? 0 : bitmap.width;
const bitmapHeight = bitmap.sourceHeight === 0 ? 0 : bitmap.height;
// @todo: updateBitmapSkin does not take ImageData
const canvas = document.createElement('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
canvas.width = bitmapWidth;
canvas.height = bitmapHeight;
const context = canvas.getContext('2d');
context.putImageData(bitmap, 0, 0);
@ -873,7 +876,7 @@ class VirtualMachine extends EventEmitter {
const storage = this.runtime.storage;
costume.dataFormat = storage.DataFormat.PNG;
costume.bitmapResolution = bitmapResolution;
costume.size = [bitmap.width, bitmap.height];
costume.size = [bitmapWidth, bitmapHeight];
costume.asset = storage.createAsset(
storage.AssetType.ImageBitmap,
costume.dataFormat,
@ -885,7 +888,10 @@ class VirtualMachine extends EventEmitter {
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
this.emitTargetsUpdate();
});
reader.readAsArrayBuffer(blob);
// Bitmaps with a zero width or height return null for their blob
if (blob){
reader.readAsArrayBuffer(blob);
}
});
}