Giter Site home page Giter Site logo

GetImageData as Color[] about raylib-cs HOT 2 CLOSED

chrisdill avatar chrisdill commented on May 12, 2024
GetImageData as Color[]

from raylib-cs.

Comments (2)

ChrisDill avatar ChrisDill commented on May 12, 2024

It shows a single element because mapPixels is a pointer and it shows the element it is pointing to. This does not mean there is only one element inside it.

You can see this by looping through the colors. Note there is a large number of colors in screendata.

unsafe
{
    var img = Raylib.GetScreenData();
    var img2 = Raylib.GetImageData(img);
    Color* mapPixels = (Color*)img2.ToPointer();

    for (int i = 0; i < img.width * img.height; i += 1)
    {
        Color color = mapPixels[i];
        // Use color here
    }

You could also use the newer Span which may be more suitable for your needs.

unsafe
{
    var img = Raylib.GetScreenData();
    var img2 = Raylib.GetImageData(img);

    Span<Color> colors = new Span<Color>(img2.ToPointer(), img.width * img.height);
    foreach (var color in colors)
    {
        // Use color here
    }
}

from raylib-cs.

horseyhorsey avatar horseyhorsey commented on May 12, 2024

Thanks. I wasn't aware of Span or the Color* asterix reference in C#. That should've rang bells from using C.

Note there is a large number of colors in screendata.

Yes, I do have a small display though which may help it get through the work! :)

from raylib-cs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.