Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I have a byte array stored in a file. I want the quickest, easiest way of viewing the image whether it is writing code or using a utility or web page.

share|improve this question

closed as not a real question by Martin Beckett, Glenn Nelson, Walter, nikie, ChrisF Feb 21 '12 at 23:31

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Do you know what format the picture is (eg. bmp, jpeg, gif, etc.)? – Hand-E-Food Feb 19 '12 at 22:03
its not in any of those formats its just a byte array containing rgb values repeating – Xavier Feb 19 '12 at 22:08
Depends on your windowing library you're using/want to use. Native Windows application? Or Linux ( / Qt / Gtk / ..)? Or MacOS? Or ...? – johannes Feb 19 '12 at 22:14
How would you know the resolution to turn it into a meaningful picture if it's just an array of bytes? What's the color depth (8,16,24 bit)? 800x600? 1024x768? 100x100? – jmq Feb 20 '12 at 6:00
-1, without knowing the OS or other requirements, 'easiest' isnt something that can be answered. – GrandmasterB Feb 20 '12 at 7:14

4 Answers 4

If your situation is that you've got a piece of data and you want to see what it looks like as RGB values, try using the PPM file format. It's trivially simple, and writing a tool to convert the byte array to PPM should be no more than a few lines of code.

PPM file format description:

share|improve this answer

Most UI frameworks will give you a Graphics object that you can write directly to. You have to know the stride for the image (I.E. how many pixels per row) and the bits per pixel. But knowing those two values, you will be able to feed the Array to a function that will render the image in a defined area.

share|improve this answer

In Java, you can create and display an image from a data array pretty easily, the example code below creates a GUI that shows a 100x100 random image constructed from an int[] array:

package testswing;

import java.awt.*;
import java.awt.image.*;
import java.util.Random;
import javax.swing.*;

public class App {
    static class MyPanel extends JPanel {
        BufferedImage b;
        Random r=new java.util.Random();

        public MyPanel() {
            int w=100;
            int h=100;
            int[] pix=new int[w*h];
            for (int i=0; i<pix.length; i++) {
            Image im= createImage(new MemoryImageSource(w, h, pix, 0, w));
            b=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
            b.getGraphics().drawImage(im, 0,0,w,h,null);
            setPreferredSize(new Dimension(b.getHeight(),b.getHeight()));

        @Override public void paintComponent(Graphics g) {

    public static void main(String[] args) {
        JFrame f=new JFrame("Hello World");

        MyPanel mp=new MyPanel();


To display your image from a file, all you need to do is load your bytes and then convert them into the appropriate int[] ARGB array. Something like:

  File f=new File("mybytes.raw");
  DataInputStream din = new DataInputStream(new FileInputStream(f));
  byte b[] = new byte[f.length()];;

Note that how you convert the bytes to the int[] ARGB format will depend on your particular image format.

share|improve this answer

I haven't tried this, but as I understand this, ImageMagick's RGB format should do just what you want.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.