Hi,
I want to read the color of one pixel from a TCastleImageControl. I found in the class TCastleImage this: Assuming the above definition, RawPixelsˆ[z, y, x] is color of pixel at position z, x, y
I can’t find an example how to do it. Who can help?
I don’t think you want to use the RawPixels because then you need to know how the color is encoded. I think.TCastleImage.GetColors( x, y, z : integer ) : TCastleColor is what you would want to use?
Thank you all! I confirm that TCastleImage.Colors, already mentioned above, would be my recommended solution too.
Note that you could also use RawPixels … but it would be more difficult. You would need to know the particular memory layout of your image descendant, which depends on the image type. E.g. for TRGBImage (RGB, no alpha), it’s a sequence of 3-byte values, and can be accessed like TRGBImage(MyImage).RGBPixels[Y * ImageHeight + X] or TRGBImage(MyImage).PixelPtr(X, Y)^. But… you likely don’t want to know all these details, it’s exactly why we created TCastleImage.Colors that just works with all image descendants and is simple
As mentioned, we also have TAbstractTextureNode.Color which is great for textures. It can do additional bilinear filtering and is generally better if you have TAbstractTextureNode instance – but this is not the case when you have TCastleImageControl.