-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot draw image via canvas context.drawImage #3216
Comments
This code compiles. Can you post more details? // What I'm guessing your variables are?
var sliceLeft = 0, sliceTop = 0, sliceWidth = 0, sliceHeight = 0;
var drawLeft = 0, drawTop = 0, drawWidth = 0, drawHeight = 0;
var context: CanvasRenderingContext2D;
var image: HTMLImageElement;
context.drawImage(
image,
sliceLeft, sliceTop,
sliceWidth, sliceHeight,
drawLeft, drawTop,
drawWidth, drawHeight
); |
Yep, you are right, there is something else behind this error. It seems what this error occurse when not all arguments (expect let sliceWidth = '';
let sliceHeight = ''; And you will get same error as I got. I know it's wrong to pass string there and that was a bug in my code because I forgot to cast it to number after |
This happens because of how we do overload resolution:
The first overload to We just don't have any way of knowing which overload you were trying to call: declare function f(x: string, y: boolean);
declare function f(x: number, y: string);
// Is the problem that x is a number, or that y is a boolean?
f(32, true);
// Is the problem that x is a string, or that y is a string?
f('foo', 'foo'); In this particular case it's more obviously bad because the parameters only differ on that first argument; the ideal type of We should run some kind of tool over lib.d.ts to detect and fix up these cases so the error messages are more useful. |
Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)' |
Hello, I'm getting this error, so please help me, |
ror): Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)' |
Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)' please help me |
Hi, i couldn't understand that fixed this issue in this post. can anyone help me on this? i am using this setup in vuejs 3
|
drawImage
call:The text was updated successfully, but these errors were encountered: