Quick Links: Gideros Home | Download Gideros | Developer Guide
Get pixel information from Bitmap or Texture
  • Is there a way to access pixel information in Gideros? Something along the lines of:
    local pixel = Texture:getPixel(x,y)
    My Gideros games: www.totebo.com
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    Maintainer Accepted Answer
    There are 2 ways
    1) using media plugin:
    local media = Media.new(imagePath)
    media:getPixel(x, y)
    media:setPixel(x, y, 255, 0, 0, 0.5)

    2) using hidden Dib class (I don't know if it still works though)

    Likes: totebo

  • I had never heard of Dib! Regrettably it crashes the player without an error.
    My Gideros games: www.totebo.com
  • So probably it is not usable anymore, due to recent changes in graphical API
  • Trying out the new RenderTarget:getPixel(). It's really slow, even with a RenderTarget of 1x1 pixel. I seem to remember reading this is expected, but can't find it in the forum.

    Is there an efficient way of getting the colour of a pixel nowadays?
    My Gideros games: www.totebo.com
  • hgy29hgy29 +1 -1
    Yes, it is slow because texture data is stored in GPU memory, and is not directly accessible by CPU. What is your use case ?
    If you need to access Bitmap data, that is something that shouldn't change, then you get grab all pixels once in a lua array (with RenderTarget:getPixels()) and look them up at will afterwise.
  • My use-case isn't entirely straightforward, but since you asked! :)

    1. Load tilemap
    2. Merge all passive tiles into one background layer
    3. Get pixel from background layer to determine which sound to play when walking on surface
    My Gideros games: www.totebo.com
  • You should pre-calculate these and have an array the same as the map with the tile detail data.
  • hgy29hgy29 +1 -1
    Since you use a tilemap, then why not just looking up in the tilemap and map sounds on a tile by tile basis instead of per pixel ?
  • totebototebo +1 -1 (+1 / -0 )
    Yeah, that would work. Thanks guys!

    Likes: SinisterSoft

    My Gideros games: www.totebo.com
  • keszegh +1 -1
    per-pixel image manipulation does work still via media class or is there now some other method?

    i guess shaders would also work (i want to morph/warp the image). any other method?
  • keszegh +1 -1
    any recommendations about best way to edit pixels of an image/morph an image?
  • keszegh +1 -1 (+2 / -0 )
    fyi i decided to use shaders to morph images.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters