Does anyone know how to convert an image into an array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does anyone know how to convert an image into an array?

I'm looking to convert small images into an array.

10th Jan 2020, 5:41 AM
Jake
4 Answers
+ 5
Which programming language? Please add it in the tags aswell. And which image format?
10th Jan 2020, 7:47 AM
Schindlabua
Schindlabua - avatar
+ 2
Do you mean the direction of the images or the actual pixels? What do you want to do with that array exactly?
10th Jan 2020, 6:16 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
+ 2
Not sure I understood all of that but I have a few thoughts: Do you know the difference between text data and binary data? Do you know how to read a file in binary mode? Are you familiar with the concept of RGB? JPG is too hard to decode by hand and so is PNG. The only format that is both common and simple to parse is BMP. It is made of a header, and then the image stored row by row, pixel by pixel. If you absolutely need JPG support you might want to look into tools like ImageMagick. Anyway you can start by writing an image class that keeps an array of `char`s or `uint8_t`s. And it stores the image like r,g,b,r,g,b,r,g,b... and maybe some functions that set and get an individual pixel. Then you can look up how to save that to a BMP file. Or ask me, I have some code lying around.
12th Jan 2020, 1:45 AM
Schindlabua
Schindlabua - avatar
+ 1
I'm using c++, the direction of the image is how I'm trying to convert into the simple 2d array. I would like to be able to convert into an array, also from the array into an image to perhaps eventually solve a conundrum that allows me to finely line the images after conversion. This is to reattribute the underlying design. Reinforcement, so to speak.
11th Jan 2020, 1:04 AM
Jake