1

Welcome,
this is not that tough please help
I use a platform (Scratch). I need to print an image using a pen
(You may not understand what I mean in the above if you don't know the platform BUT)
What I need is to convert the image (below), to hex triplet array.

Image to be converted

(Note I don't need the above image to be converted I need to know how to convert any image)

Hex triplet array sample

note: this one(above) is only a sample.

For better Understanding of hex array and image



I am familiar with java ,python,javascript.... most popular language
Give me how to convert image to hex triplet array using any language or tool

if you know the platform (scratch) you may get a hint here


Neptotech -vishnu
  • 1,096
  • 8
  • 23
  • Java: ImageIO, [BufferedImage](https://docs.oracle.com/javase/10/docs/api/java/awt/image/BufferedImage.html) could do it by pixel, or by raster (faster, but varies w.r.t. image type). I hope you are aware you got columns by row, where as an image has rows by column. A rotation by a quarter might be an optimisation. – Joop Eggen Nov 23 '21 at 08:20
  • @JoopEggen how to do that can you provide the answer with code – Neptotech -vishnu Nov 23 '21 at 09:36

1 Answers1

0
    Path path = Paths.get("... .png");

    System.out.println("Image: " + path);
    try {
        BufferedImage image = ImageIO.read(path.toFile());

        int w = image.getWidth();
        int h = image.getHeight();
        for (int x = 0; x < w; ++x) {
            for (int y = 0; y < h; ++y) {
                int rgb = image.getRGB(x, y);
                System.out.printf("%06X%n", rgb & 0xFF_FF_FF);
            }
            System.out.println();
        }
        System.out.println("Done");

getRGB delivers the color in ARGB format.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    Thanks i just used print writter instead of Printing to console because my IDE can't support more words to print in console `PrintWriter output = new PrintWriter("output.txt"); output.println(hex);` – Neptotech -vishnu Nov 27 '21 at 07:03