Skip to content
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

PNG images duplicate #5

Open
ajmeese7 opened this issue Jan 8, 2022 · 1 comment
Open

PNG images duplicate #5

ajmeese7 opened this issue Jan 8, 2022 · 1 comment

Comments

@ajmeese7
Copy link

ajmeese7 commented Jan 8, 2022

When manipulating PNG images with transparency, you can see a duplicate of the image that is scaled down:

image

Any suggestions on how to fix this? Thanks!

@iwandejong
Copy link

Hi, what you can do is to create a temp canvas and transpose it to the original canvas as follows:
`var tempCanvas = document.createElement('canvas');
tempCanvas.width = scaledW;
tempCanvas.height = scaledH;

var tempCtx = tempCanvas.getContext('2d');
tempCtx.mozImageSmoothingEnabled = false;
tempCtx.webkitImageSmoothingEnabled = false;
tempCtx.imageSmoothingEnabled = false;

tempCtx.drawImage(image, 0, 0, scaledW, scaledH);

var ctx = canvas.getContext('2d');
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;

ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(tempCanvas, 0, 0, scaledW, scaledH, 0, 0, canvas.width, canvas.height);

`
Let me know if it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants