0

I have an image stored as a png (I could convert it to bmp too). I want to open it in JavaScript and get the raw RGB bytes. It is enough if this works locally in Chrome. So I open ./index.html in the browser which loads an image in the same directory, e.g. with <img src=myimage.png>. However, I need the proper original data, without any compression or artifacts. I can't use NodeJS.

I saw a similar question, Get image data in JavaScript, but it requires that the image is hosted somewhere. I'm also not sure how to get the raw RGB bytes, the results I got from trying those examples looked like they were still encoded as png.

EDIT: As one of the answers to the other SO question mentions, a canvas will re-encode the data and reading from it won't give me exactly the same values as in the original.

M.K.
  • 346
  • 3
  • 14
  • put it on a canvas then - https://stackoverflow.com/questions/7373851/reading-the-rgb-value-of-a-canvas-pixel – Daniel A. White Jan 11 '19 at 17:06
  • The other SO question I mentioned says that this wouldn't give me the original data, but slightly modified re-encoded data. – M.K. Jan 11 '19 at 17:07
  • " it requires that the image is hosted somewhere." Didn't you say image is hosted somewhere, in the same directory as your index.html? – JeffUK Jan 11 '19 at 17:13
  • @JeffUK, the XHR request doesn't work with something like ``, it requires HTTP. I could start a web server on localhost, but I would prefer to avoid that. – M.K. Jan 11 '19 at 17:16
  • Does this help? https://stackoverflow.com/questions/39606016/javascript-reading-local-text-file-from-specific-path-without-xmlhttprequest-an if it was a BMP you could read it in as a string and parse it yourself? – JeffUK Jan 11 '19 at 17:20
  • I would prefer if I didn't have to use a library to do this. And is manually parsing the BMP seriously the only option for something this simple? – M.K. Jan 12 '19 at 09:06

0 Answers0