Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Co-ord of pixel in GetPixels32 array

Discussion in 'Scripting' started by Wannabeuk, Nov 20, 2017.

  1. Wannabeuk

    Wannabeuk

    Joined:
    Feb 19, 2013
    Posts:
    62
    I'm having an issue working this out, I'm loading a png and using GetPixels32 to grab all the pixels into an array of Color.

    I then loop through my texture width and hight (using x, and y as the values). How would i then get the correct pixel (x,y) from the array of colors?

    Hopefully this will explain it a little if I've not made sense above.

    Code (CSharp):
    1. Color32[] pixels = pixmap.GetPixels32();
    2. for (int x = 0; x < pixmap.width; x++)
    3. {
    4.    for (int y = 0; y < pixmap.height; y++)
    5.     {
    6.         Color32 color = pixels[HERE?];
    7.      }
    8. }
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    From the docs:
    Here's an example of how to work with them:
    https://www.dotnetperls.com/flatten-array
     
  3. Wannabeuk

    Wannabeuk

    Joined:
    Feb 19, 2013
    Posts:
    62
    Thanks for the reply. That's exactly what i needed. Thanks