Skip to content

How to create image #584

Answered by Squareys
zaichenhu asked this question in Q&A
Discussion options

You must be logged in to vote

You can allocate the data and then use .pixels<T>() to type cast the char data to some pixel type, e.g.:

    constexpr Vector2i size{2, 2};
    Image2D image{{}, PixelFormat::RGBA32UI, size,
        Containers::Array<char>{NoInit, size.product()*sizeof(UnsignedInt)*4}};
    auto pixels = image.pixels<Vector4ui>();
    
    const int x = 0;
    const int y = 1:
    pixels[y][x] = Vector4ui{345, 0, 123, 678};

Note that to access a pixel, you pick the row first, then the column in the row, which is why x and y are in a different order than I used to expect.

For some pixel types, you might need to add row padding etc. I think there was a function to compute the required data size for an image…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mosra
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #581 on August 18, 2022 10:36.