0

I have a massive string of hexadecimal numbers. I want to make an image out of this string where each pixel's colour value is defined by (the first, second, third ...) 6-letter strings from this massive string. I'm hoping the image will look something like this: https://i.stack.imgur.com/8jKGx.jpg. Although there will be many more pixels.

I'm a noob when it comes to coding so any help/pointers would be massively appreciated! I've done some tests by entering the hexadecimal values manually into illustrator but it takes far too long.

2 Answers2

0

You should loop through the string, counting by 6, to pull out each individual color. I recommend using python, because you can also use a library to create the image once you have all the values.

Take a look at this question for tips on looping: Iterate over a string 2 (or n) characters at a time in Python

Community
  • 1
  • 1
John G
  • 7
  • 5
0

This should work. This will create a BufferedImage with a defined height and width from the string hexString. You can then draw it to a JPanel or save it to a file.

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
for(int i = 0; i < hexString.length(); i += 6){
    int x = i % width;
    int y = (int) Math.floor(i / width);
    Color hexColor = new Color(Integer.parseInt(hexString.substring(i, i + 6), 16);
    g.drawRect(x, y, 1, 1);
}
James McDowell
  • 2,668
  • 1
  • 14
  • 27