Answer the question
In order to leave comments, you need to log in
How to get image from array in java swing?
I read somewhere that you can convert an array with numbers into an image, how to do it in java swing?
Answer the question
In order to leave comments, you need to log in
With what numbers exactly? To what image? And most importantly - what does Swing have to do with it?
If "numbers" means an array of bytes containing, for example, a JPEG-encoded image that you want to have in an ImageIcon (which seems to me the most likely interpretation of the question in the context of Swing), then, for example, like this:
byte[] arBytes;
...
ImageIcon icon = new ImageIcon(arBytes);
int[] arInts = {0,1,2,3,4,5,6,7,8,9};
...
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
g2d.setPaint(Color.red);
g2d.setFont(new Font("Serif", Font.BOLD, 18));
FontMetrics fm = g2d.getFontMetrics();
int x = 5;
for(int i : arInts){
String s = (new Integer(i)).toString();
g2d.drawString(s, x, 5);
x += fm.stringWidth(s) + 5;
}
g2d.dispose();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question