Way to get a pixel colour from an image


As a developer, it is near impossible to get the pixel RGB colour from an image, without using external methods.

If this feature were to be added, I would be able to use the upcoming StudioService:PromptImportLocalAsset() alongside it for my heightmap importer plugin. I would get the colour value of each pixel within the image and use that, removing the need for an external program to convert the heightmap and texture map images into something Studio can read.

It would be nice to have something as seen in this post:

If the feature was something similar to the quote above, I could run a simple for loop to get each pixel colour within the image. I would also be able to get the image size (Provided the function returns nil if the pixel did not exit), although another feature request for that would probably be better.


It would help if you provided a use case.


Is this alright?


This sounds like an XY problem–wouldn’t the solution in that case be an API for getting image size?


That was more of an example, I’m not suggesting that currently as the main reason for this feature request. This is primarily for getting the colour of an image.


I’m working on a space game, which is currently using textures wrapped on spheres for the planets. It’d be incredibly useful if I could do a little bit of math to check where the cursor aligns with the sphere, convert that to a Vector2 value or something, and then check the RGB colour at that point on the image in order to see if the player was hovering their mouse over blue-ish colour (aka; ocean), in order to prevent buildings from being placed on top of oceans.

Edit: I just realized that I’m in the reference post, where I gave the exact same example. Whoops.


There’s also LocalAsset:GetFileContentsBinary(), which returns a string. It’s cumbersome, but you can probably try decoding it yourself. I found a png decoder written in pure lua 5.1, and it’s licensed in BSD-2 (not copyleft): https://github.com/kartik-s/lua-png Doesn’t work on compressed pngs, which is what you’ll work with 99% percent of the time :confused:


I would love to have a way to get a pixel colour from a image. I would use this to determine the average or most common colour of an image, to use in procedurally generating colour-specific particle, beam, and lighting effects.


On that note, this feature would make my request for the new Lua game page possible:

So this feature would help drastically with Roblox’s push for a completely Lua mobile interface that looks and feels good