MZ How to flip / mirror a bitmap horizontally and vertically

Does anyone know in RMMZ Javascript if it's possible to flip a bitmap object horizontally or vertically?

I was wondering if Bitmap.blt might do it?
Note: It has to be a Bitmap not a sprite, as I'm doing other manipulations to bitmap along side of wanting to flip it within the plugin I'm working on.
Yep, you should be able to blit it to a new bitmap's canvas, e.g. (untested):
JavaScript:
// Output bitmap.
const bmp = new Bitmap();
// Load source & blit to output once loaded.
ImageManager.loadPicture("Actor1_1").addLoadListener(b => {
  const { width, height } = b;
  bmp.resize(width, height);
  const ctx = bmp._context;
  ctx.save();
  ctx.scale(-1, -1);  // flip X & Y
  bmp.blt(b, 0, 0, width, height, 0, 0);
  ctx.restore();
});
Yep, you should be able to blit it to a new bitmap's canvas, e.g. (untested):
JavaScript:
// Output bitmap.
const bmp = new Bitmap();
// Load source & blit to output once loaded.
ImageManager.loadPicture("Actor1_1").addLoadListener(b => {
  const { width, height } = b;
  bmp.resize(width, height);
  const ctx = bmp._context;
  ctx.save();
  ctx.scale(-1, -1);  // flip X & Y
  bmp.blt(b, 0, 0, width, height, 0, 0);
  ctx.restore();
});
In theory you should translate ctx to the lower right corner of the area after of before scale.
Thanks guys, both of you got me on the right track, ultimately I ended up with the following (tested):


JavaScript:
static flipBitmap(bitmap,flipHorizontal, flipVertical) {
        const newBitMap = new Bitmap();
        const { width, height } = bitmap;
        newBitMap.resize(width, height);
        const ctx = newBitMap._context;
        ctx.save();
        var { xScale, yScale, xTranslate, yTranslate} =0;
        if (flipHorizontal) {
            xScale=-1;
            xTranslate=-width;
        }
        else
        {
            xScale=1;
            xTranslate=0;
        }
        if (flipVertical) {
            yScale=-1;
            yTranslate=-height;
        }
        else
        {
            yScale=1;
            yTranslate=0;
        }
        
        ctx.scale(xScale, yScale); 
        ctx.translate(xTranslate,yTranslate)
        newBitMap.blt(bitmap, 0, 0, width, height, 0, 0);
        ctx.restore();
        return newBitMap;
    }

Original thread: https://forums.rpgmakerweb.com/threads/how-to-flip-mirror-a-bitmap-horizontally-and-vertically.174901/