javascript - Convert an image to ImageData (Uint8ClampedArray) -


i have image example "img/myimage.jpg" convert uint8clampedarray format (as shown in image). enter image description here

for what? using library after long process converts images format, have others images need convert them on own same format. how can it? excuse ignorance

var frames = animator.frames; var res_c = document.getelementbyid("result"); var res_ctx = res_c.getcontext('2d'); (var x = 0; x < frames.length; x++) {   //***frames imagedata (uint8clampedarray)***   res_ctx.putimagedata(frames[x],0,0);   console.log(frames[x])   gif.addframe(res_c,{copy:true,delay: 120}); } 

i need convert images in imagedata (uint8clampedarray) add others frames

you can use image constructor, canvasrenderingcontext2d.drawimage() , canvasrenderingcontext2d.getimagedata() create imagedata object image file.

const canvas = document.queryselector("canvas"); const ctx = canvas.getcontext("2d"); const width = 300; const height = 311;  const image = new image; image.src = /* blob url, "/path/to/image/served/with/cors/headers" */; image.onload = () => {   ctx.drawimage(image, 0, 0);   imagedata = ctx.getimagedata(0, 0, 300, 311);   console.log(imagedata); } 

Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -