Hi all,
I am currently trying to display images that are taken from the fills of a selected object within a plugin. I am following this guide, where I get the image by hash and obtain the image bytes array.
const getImageByHash = async (hash: string) => {
console.log('Image found');
const imageHash = figma.getImageByHash(hash);
const imageArray = await imageHash.getBytesAsync();
console.log('Posting image byte array to Figma...');
figma.ui.postMessage({type: 'renderImage', img: imageArray});
};
I am trying to then display the image in the plugin, but haven’t been successful in figuring out how to do so.
I’ve tried converting the image to a Blob url and using that as the image src but it doesn’t seem to work.
const blob = new Blob([texture], {type: 'image/png'});
const blobURL = URL.createObjectURL(blob);
const image = await new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = () => reject();
img.src = blobURL;
});
I am using React for the Figma plugin frontend. Any advice for this would be greatly appreciated!