apple2js/test/util/image.ts
Will Scullin af57378852
Videomode refactor 2 (#80)
Remove globals from video implementations to allow further refactoring. Experiment with testing video modes.
2021-05-25 12:08:10 -07:00

10 lines
359 B
TypeScript

export const createImageFromImageData = (data: ImageData) => {
const canvas = document.createElement('canvas');
canvas.width = data.width;
canvas.height = data.height;
const ctx = canvas.getContext('2d')!;
ctx.putImageData(data, 0, 0);
const url = canvas.toDataURL('image/png');
return Buffer.from(url.split(',')[1], 'base64');
};