Javascript createImageBitmap返回一个空图像

Javascript createImageBitmap返回一个空图像,javascript,image,Javascript,Image,我正在使用createImageBitmap转换worker中的图像 blob有数据,定位是有效的,它们是负数,但我尝试使用0和相同的问题 createImageBitmap(blob, -pos.x + 100, -pos.y + 100, 200, 200).then(data => { resolve(data)}) 出来的数据是 但是,当您尝试将其转换为blob时 const canvas = document.createElement('canvas

我正在使用createImageBitmap转换worker中的图像

blob有数据,定位是有效的,它们是负数,但我尝试使用0和相同的问题

 createImageBitmap(blob, -pos.x + 100, -pos.y + 100, 200, 200).then(data => {
            resolve(data)})
出来的数据是

但是,当您尝试将其转换为blob时

const canvas = document.createElement('canvas')
      canvas.height = img.height
      canvas.width = img.width
      const context = canvas.getContext('bitmaprenderer')
      context.transferFromImageBitmap(img)

canvas.toBlob((blob)=> ..
水滴是空的

有没有关于我错在哪里的线索

这是一个具有bitmaprenderer上下文的

无论出于何种原因,HTMLCanvasElement.toBlob和HTMLCanvasElement.toDataURL的结果都将是完全透明的图像

它们不支持HTMLCanvasElement中显示的当前活动位图缓冲区

这可以通过将画布附加到文档来演示:

取回https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png' .thenr=>r.blob .thenb=>createImageBitmapb,120120 .thenimg=>{ 返回新的Promiser=>{ //创建画布 const canvas=document.createElement'canvas'; //将其调整为图像位图的大小 canvas.width=img.width; canvas.height=img.height; document.body.appendcanvas; //在Bitmarender上下文上传输 canvas.getContext'bitmaprenderer' 。从ImageBitMapimg传输; //把它当作一团拿回来 canvas.toBlobres; }; } .thenblob=>{ var img=document.body.appendChildnew Image; img.src=URL.createObjectURLblob; }; img{ 边框:纯红; } 帆布{ 边框:纯绿色;
}它们可以是零。第一个blob来自一个在Frame webGL中生成的大图像,我将它传递给一个工作人员进行图像处理和调整大小,因为它冻结了浏览器。第一个blob是有效的,包含数据。It控制台记录为具有大量数据。我试过pos.x和y=0,没有区别。谢谢@kaido-你帮了大忙。