Rotate an image that is in an array

Asked

Viewed 151 times

0

Good afternoon, I have a color image in an array 1D, for example:

int[] image = {255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 255, 0, 255, 0, 255, 0, 0};

This array has 6 pixels, red, green, blue, blue, green, red, imagining that these pixels are positioned horizontally:

| Vermelho | Verde | Azul     |
| Azul     | Verde | Vermelho |

How I could rotate this image so that the pixel layout becomes vertical:

| Azul     | Vermelho |
| Verde    | Verde    |
| Vermelho | Azul     |

I want to place this rotated array in another 1D array.

  • 1

    The difference is. Only when retrieving or printing values does the array continue in the same way

  • You want to distribute each color group in indices with 3 difference, that’s it?

  • Sorry, maybe I have expressed, badly, I need to insert this new image in a new array 1D, for an image that contains only 3 pixels will really only change in the part of saving the file, but when it involves more lines, then it is necessary to change this data. I improved the example, maybe it’s clearer. Abrass

1 answer

1


If you are going to work with the one-dimensional array, then there is no such concept of horizontal or vertical. What you can do is replace the position of the colors.

But if you want to turn the array into a two-dimensional one, then I suggest reading the answers to these two questions that will help you a lot:

It is possible to rotate colors in a two-dimensional array and then convert back to one one-dimensional.

  • I’ve been taking a look, but I’ve come to the conclusion that it doesn’t apply to my problem, because the array I have represents RGB colors, I would have to turn this into a 3D array, I think.

  • Finally got, really this was the solution, turn into a 2D array to then rotate, works even with color images, thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.