Skip to content

Images

The images area loads pictures and draws them in your windows. Wraith holds them on the GPU for you, in the overlay and anywhere else they get drawn.

images.load(path) reads and decodes a file on a worker, so the game doesn’t stall. A path that isn’t full is in your plugin’s own folder, like images/logo.png. Anywhere outside your plugin’s folders needs "files": true in your permissions. It reads PNG, JPEG, BMP, TGA and the first frame of a GIF. Sides over 16384 pixels get refused, and a file that’s missing fails with NotFound.

import { Wraith } from "wraith";
const images = Wraith.images();
const logo = await images.load("images/logo.png");

Already have the bytes? images.decode(bytes) decodes them right there, so keep it off the render thread. Raw RGBA pixels go to images.create(width, height, rgba). An image’s dimensions() gives its width and height in pixels.

images.draw(image, size) draws it in the current window, inside a window’s draw or a draw callback. A zero size draws it at its own size.

import { Wraith } from "wraith";
Wraith.ui().addWindow({ title: "Logo", icon: "image" }, () => {
if (!logo) return;
images.draw(logo, { x: 0, y: 0 }); // its own size
images.draw(logo, { x: 64, y: 64 }); // 64 by 64
});

For anything else, an image’s texture() gives ImGui’s ImTextureRef, for calls like imgui.ImageButton or a draw list’s AddImage. It’s only good for that frame.

destroy() frees it now, and it leaves the GPU over the next frames. Calling it twice is fine. Whatever you don’t destroy goes when your plugin stops. In a tweak, images go when the tweak turns off.

logo.destroy();

display.capture(point) copies the next frame, before_overlay or after_overlay, as a Capture with its width, height, pitch, format and pixels. It needs "capture": true in your permissions. images.create makes an image from pixels you’ve made. Encoding PNGs and tone-mapping HDR are Zig only so far.

import { Wraith } from "wraith";
const shot = await Wraith.display().capture("after_overlay");
// shot.width, shot.height, shot.pitch, shot.format and shot.pixels

Made with ♥ by Asgard