MZ How to "Blt" a picture onto a bitmap?

Would anyone know why a bitmap loaded via loadPicture can't be blited onto another bitmap, while a bitmap loaded via loadCharacter can be blited onto another bitmap?

This code works:

JavaScript:
let img_name = 'Actor1' // A spritesheet name in your character folder
let img = ImageManager.loadCharacter(img_name)

let output = new Bitmap(Graphics.width, Graphics.height)
output.fillAll('#252525')
output.blt(img, 0, 0, output.width, output.width, 0, 0)

let s = new Sprite(output)
SceneManager._scene.addChild(s)

This code does not:

JavaScript:
let img_name = '_Stand_D' // A picture in your img/piciture folder
let img = ImageManager.loadPicture(img_name)

let output = new Bitmap(Graphics.width, Graphics.height)
output.fillAll('#252525')
output.blt(img, 0, 0, output.width, output.width, 0, 0)

let s = new Sprite(output)
SceneManager._scene.addChild(s)

Thank you.
Both those examples will work only if the image is already in memory. This is because Bitmap#blt immediately draws directly from image data, and disk access times (even for SSD) are much longer than the time between processing successive lines of code.

Instead you can use a load listener, e.g. (untested):
JavaScript:
// Create scene sprite
const sprite = new Bitmap(Graphics.width, Graphics.height);
SceneManager._scene.addChild(sprite);

// Load picture and blit to that sprite when ready
ImageManager.loadPicture('_Stand_D').addLoadListener(bmp => {
  sprite.bitmap.fillAll('#252525');
  sprite.bitmap.blt(bmp, 0, 0, bmp.width, bmp.height, 0, 0);
});
Unless you have a specific reason to blit the whole thing, though, I think it'd be cheaper and easier to just init a new sprite from the bitmap, e.g.
JavaScript:
SceneManager._scene.addChild(new Sprite(ImageManager.loadPicture('_Stand_D')));
The Sprite wrapper should automatically refresh its appearance when the image data is fully loaded.

[Edit: replaced _StandD with the name from the OP's post, _Stand_D. Whoops.]
Both those examples will work only if the image is already in memory. This is because Bitmap#blt immediately draws directly from image data, and disk access times (even for SSD) are much longer than the time between processing successive lines of code.

Instead you can use a load listener, e.g. (untested):
JavaScript:
// Create scene sprite
const sprite = new Bitmap(Graphics.width, Graphics.height);
SceneManager._scene.addChild(sprite);

// Load picture and blit to that sprite when ready
ImageManager.loadPicture('_StandD').addLoadListener(bmp => {
  sprite.bitmap.fillAll('#252525');
  sprite.bitmap.blt(bmp, 0, 0, bmp.width, bmp.height, 0, 0);
});
Unless you have a specific reason to blit the whole thing, though, I think it'd be cheaper and easier to just init a new sprite from the bitmap, e.g.
JavaScript:
SceneManager._scene.addChild(new Sprite(ImageManager.loadPicture('_StandD')));
The Sprite wrapper should automatically refresh its appearance when the image data is fully loaded.
@caethyril thank you sir!

It works just fine!
Great, you're welcome! 👋

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-blt-a-picture-onto-a-bitmap.149472/