mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Use bitmap source width
This commit is contained in:
parent
33f4482127
commit
aeea9c1a51
1 changed files with 10 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue