0
having access to the pixels of any image through the SFML library, my goal is captured and convert them to characters by placing in a new matrix (image) and then display it. For that I checked the size of the image:
sf::Vector2u tam = imagem.getSize();
int largura = tam.x;
int altura = tam.y;
To capture the RGB format, use the following code:
// O ponteiro dos pixel originais em RGBA.
const sf::Uint8* pixels = imagem.getPixelsPtr();
Pixel* rgba = (Pixel*) pixels;
// Vetor que armazenará os pixels.
sf::Uint8* saida = new sf::Uint8[4 * largura * altura];
int tamanho = 4 * largura * altura;
for (int i = 0; i < tamanho; i++)
{
saida[i] = pixels[i];
}
What I’m doing is creating a vector that is receiving the RGBA, but still no conversion to characters, and that’s one of my doubts as is a vector as I will control when it must break the line to form the correct image?
Wouldn’t it be better to do it with a matrix?
My other question is how do I convert these pixels into characters?
I tried that way, but without success:
for (int i = 0; i < tamanho; i++)
{
if (atriz[i][j]>=9,4*8)
saida[i] = '@';
}
Hi! Still not able to solve that question? Did you consult the links about ASCII art? They were useful? Link 1, Link 2 and Link 3
– carlosrafaelgn
You can even use an array, but it is not necessary. You can use the hint given in a reply to your other question:
pixels[4 * (y * largura + x) + 0]
returns the pixel R component in the coordinate(x, y)
.+ 1
gives you back G,+ 2
to B, and+ 3
component A.– carlosrafaelgn
There is an error in your second code. Despite the code
if (atriz[i][j]>=9,4*8)
compile correctly in C/C++, I don’t believe it is producing the result you expect. What you meant by9,4*8
?– carlosrafaelgn
Hello @carlosrafaelgn all right?! I finally managed to do what I wanted to hehe :D, I was doing the calculations of wrong conversions, when getting ready put the open source code. att
– Emanoel
Cool! It’ll get interesting! :)
– carlosrafaelgn