javascript - Problems with canvas processing images
扔个三星炸死你
扔个三星炸死你 2017-06-10 09:49:16
0
3
1028

I need to use canvas to process a picture uploaded by the user. The size uploaded by the user may be very large, for example, it will exceed the width and height of the current browser window, so I scale it to the visible area of ​​​​the browser. inside, and then draw it onto the canvas, but this is equivalent to reducing the user's image. After the canvas is processed, is there a way to restore the processed image to its original size without causing blur?

I’m really convinced. Who will give Gu Yue and Jack a thumbs up? What they said is the right method!

扔个三星炸死你
扔个三星炸死你

reply all(3)
左手右手慢动作

The width and height of the canvas are set to the same as the original size of the image, but style is used to scale the canvas to the visible area. This way the image will not be compressed

仅有的幸福

Thank you for the invitation. Although I would like to answer you, I haven’t tried it, so I don’t know. Of course you can try it yourself, it won’t take much time anyway.
But we can change our thinking. Why do you want to reduce the image and draw it on canvas?
Isn’t it possible to scale the image to the visible area without max-width or max-height? This is just the image being reduced on the surface. In fact, the naturalWidth and naturalHeight have not changed, so the zoom restoration is actually unnecessary.
You can use img to display within the visible area of ​​the browser. Do not use canvas. Canvas is used to process images. If you have to display the image being processed by the canvas, then you can just create another off-screen canvas, then scale the related processing proportionally, and finally save the off-screen canvas.
I don’t know if I made it clear.

洪涛

HTML5 image upload preprocessing https://juejin.im/entry/5933e...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template