Skip to content

OffscreenCanvas does not have toDataURL ability #14713

@troy351

Description

@troy351
Description of the problem

if ( image instanceof HTMLCanvasElement ) {
canvas = image;
} else {
if ( typeof OffscreenCanvas !== 'undefined' ) {
canvas = new OffscreenCanvas( image.width, image.height );
} else {
canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = image.width;
canvas.height = image.height;
}
var context = canvas.getContext( '2d' );
if ( image instanceof ImageData ) {
context.putImageData( image, 0, 0 );
} else {
context.drawImage( image, 0, 0, image.width, image.height );
}
}
if ( canvas.width > 2048 || canvas.height > 2048 ) {
return canvas.toDataURL( 'image/jpeg', 0.6 );
} else {
return canvas.toDataURL( 'image/png' );
}

if canvas is an instance of OffscreenCanvas , the call canvas.toDataURL will throw an error, should avoid it,

Three.js version
  • Dev
  • r95
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions