In Kotlin, I can set a bitmap to be 500x500 and use ScaledBitmap to load an image in to it at that size without wasted memory junk as far as I know.
Now I am trying to do this in javascript so I can have my website display it’s images to scaled sizes of my choosing without having to load the full size of every image first or manually making and uploading multiple sizes.
Everything I’m seeing says there is no way in JS. My ELI5 here is WHY? What makes Kotlin have this but not JS?
sloplike screenshots for reference
Because neither Kotlin nor JavaScript load images.
Kotlin is a Java runtime language, whose most common use is being compiled to bytecode to run full desktop or server applications.
JavaScript is a web browser language, whose most common use is being sent alongside HTML to augment the behavior of a web browser.
Since Kotlin tends to operate outside of a browser sandbox, it makes sense to expose JRE features to allow memory efficient image handling.
In contrast, JavaScript within a browser sandbox only gets images loaded by the web browser, which were already sent over the Internet and loaded in their full size.
( There are ways to run JavaScript outside a browser and Kotlin within, but that’s a bigger topic.)