简体   繁体   中英

createImageBitmap with resize: doesn't work on Chrome?

Looking at the MDN page for createImageBitmap it states that Chrome supports the options parameter from 52 onwards. But in testing with Chrome 57, I can't seem to get the resizeWidth or resizeHeight options to work. I've got a demo running here:

https://codepen.io/anon/pen/YVwrXN

From my understanding, what I've provided should end up with an image bitmap half the size of the original image being drawn to the canvas tag, but it appears to be full size (I know I can rescale in drawImage() but that's not what I'm looking for here). I found some Chromium notes on implementing it that makes it sound like it should work, so I'm wondering if I'm doing something wrong.

As of today, (on both chrome 60 canary and stable 57) you still need to set the Experimental canvas features flag in chrome://flags .

I agree that MDN page should state this.


Edit 2021:
Chrome now supports this natively. But other browsers still don't (Safari doesn't support the API at all). If you need this for cross-browsers projects, I wrote a createImageBitmap monkey-patch which enables this feature in all browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM