mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -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.rotationCenterX = rotationCenterX;
|
||||||
costume.rotationCenterY = rotationCenterY;
|
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
|
// @todo: updateBitmapSkin does not take ImageData
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = bitmap.width;
|
canvas.width = bitmapWidth;
|
||||||
canvas.height = bitmap.height;
|
canvas.height = bitmapHeight;
|
||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
context.putImageData(bitmap, 0, 0);
|
context.putImageData(bitmap, 0, 0);
|
||||||
|
|
||||||
|
@ -873,7 +876,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
const storage = this.runtime.storage;
|
const storage = this.runtime.storage;
|
||||||
costume.dataFormat = storage.DataFormat.PNG;
|
costume.dataFormat = storage.DataFormat.PNG;
|
||||||
costume.bitmapResolution = bitmapResolution;
|
costume.bitmapResolution = bitmapResolution;
|
||||||
costume.size = [bitmap.width, bitmap.height];
|
costume.size = [bitmapWidth, bitmapHeight];
|
||||||
costume.asset = storage.createAsset(
|
costume.asset = storage.createAsset(
|
||||||
storage.AssetType.ImageBitmap,
|
storage.AssetType.ImageBitmap,
|
||||||
costume.dataFormat,
|
costume.dataFormat,
|
||||||
|
@ -885,7 +888,10 @@ class VirtualMachine extends EventEmitter {
|
||||||
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
|
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
|
||||||
this.emitTargetsUpdate();
|
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