[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
4Archive logo
hey /g/, how would i go about writing every...
If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /g/ - Technology

Thread replies: 14
Thread images: 6
hey /g/, how would i go about writing every single rgb value in pic related in a text file automatically? is there some format that stores data like this?
>>
array obv
>>
You can write a program to do it very easily.
>>
File: values.jpg (101 KB, 1000x445) Image search: [iqdb] [SauceNao] [Google]
values.jpg
101 KB, 1000x445
Well that's a JPEG so you're already fucked.
But if you had it as a lossless file, convert it to a BMP and open the image in a hex editor - pic related.
It's relatively easy to suck the pixel data out of a lossless file. BMP is the easiest imo.
>>
>>52486492
Computers are magic, fucking magic.
>>
>>52486466
>>52486490
>>52486492
This was my first thought, but I cannot code. I might do the BMP thing because I do have the losless file, but then is there a way to convert that hex data into plaintext numbers for RGB automatically?
>>
>>52486555
literally copy and paste and some basic math bro

Convert the original to a BMP and upload it, I'll check it out and hold your hand
>>
>>52486626
dont have it on this pc, but dont worry. you can bet if i have more technical trouble i will be back on /g/ the very next day.

thanks all
>>
File: fag.png (160 B, 32x32) Image search: [iqdb] [SauceNao] [Google]
fag.png
160 B, 32x32
>>52486671
well i'll teach you anyway. i made a BMP but i can't upload it so here's a PNG representation of it
>>
>>52486555
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {

public static void main(String[] args) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("input.jpg"));
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
int rgb = img.getRGB(x, y);
String outputFile = "output.txt";
FileWriter fw = new FileWriter(outputFile,true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("#"+Integer.toHexString(rgb).substring(2).toUpperCase()+"\n");
bw.close();
}
}
} catch (IOException e) {
}

}
}


prints in this format
#B8ABB5
#B8ABB5
#B7AAB4
#B7AAB4
#B7AAB4
#B7AAB4
#B7AAB4
>>
>>52486671
>>52486770
next up, open it in a hex editor and find where the pixel data is
In this image it's at 0x36
>>
>>52486786
lastly copy that shit to a text editor and run a script/record a macro where you separate the AB CD EF AB CD EF to:
#ABCDEF
#ABCDEF
etc
>>
>>52486828
Can confirm it is literally this easy, OP. Just in case you though you were somehow being /g/entoo'd on
>>
>>52486422
I wrote pic related program to do that
Here's the code
#include <stdio.h>
int main(int * argc, char * argv[])
{
FILE *in;
in = fopen("out.ppm", "wb");
int r = 0, g = 0,b=0;
fprintf(in, "P6\n5527 3000\n255");
while(r < 256)
{
while(g < 256)
{
while(b < 256)
{
b++;
fputc(r,in);
fputc(g,in);
fputc(b,in);
}
b = 0;
g++;
}
r++;
g = 0;
}
fclose(in);
return 0;
}


Also you should read up on this file format, it is far easy to implement as compared to even BMP
>https://en.wikipedia.org/wiki/Netpbm_format
Thread replies: 14
Thread images: 6
Thread DB ID: 445566



[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vip /vp / vr / w / wg / wsg / wsr / x / y] [Search | Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.
If a post contains personal/copyrighted/illegal content, then use the post's [Report] link! If a post is not removed within 24h contact me at [email protected] with the post's information.