r/learnjavascript • u/CodeWithAhsan • May 18 '22
Using the new createImageBitmap() method to convert blob into image bitmap in JavaScript
160
Upvotes
2
1
u/_maximization May 19 '22
Nice video!
Tip: instead of awaiting and immediately returning createImageBitmap you can just return it directly without awaiting. Because you're not doing anything with the image inside getImageFromBlob.
In your case, the value is unwrapped from a Promise then wrapped in a Promise again when returning. You might as well return the initial Promise directly:
const getImageFromBlob = async (blob) => {
return createImageBitmap(blob);
};
2
u/Technomancer97 May 19 '22
This is awesome! Thanks.