Way to get a pixel colour from an image


#1

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.


#2

It would help if you provided a use case.


#3

Is this alright?


#4

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


#5

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.


#6

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.


#7

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:


#8

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.


#9

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