0

I have a colour image that is been stored in a 3D array and now I want to display this data or the image on to a JPanel. My code read function is as follows :

public void readImage(String filename) throws Exception {
    String filenameExtension = filename.substring(filename.lastIndexOf('.')+1);
    File fileImage = FileChosen;
    Iterator imageReaders = ImageIO.getImageReadersBySuffix(filenameExtension);

    ImageReader imageReader;

    if(imageReaders.hasNext())
        imageReader = (ImageReader)imageReaders.next();
    else
        throw new IOException("Unsupported image format");

    FileImageInputStream imageInputStream = new FileImageInputStream(fileImage);

    imageReader.setInput(imageInputStream);

    ImgWidth = imageReader.getWidth(0);
    ImgHeight = imageReader.getHeight(0);

    BufferedImage bufImage = imageReader.read(0);
    imageInputStream.close();

    WritableRaster wRaster = bufImage.getRaster();

    //int numBands = wRaster.getNumBands();
            System.out.println(ImgWidth);
            System.out.println(ImgHeight);


    imageArray = (new double[ImgHeight][ImgWidth][ColourLevels]);

    // get the samples and normalize to between 0 and 1
    for(int row = 0; row < ImgHeight; row++)
        for(int col = 0; col < ImgWidth; col++)
            for(int level = 0; level < ColourLevels; level++)
                imageArray[row][col][level] = (wRaster.getSample((col), (row), level) / 255.0);

} // end read method`

Now I want to print the data stored in the imageArray[][][] in to a panel, how can I do that?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1912520
  • 31
  • 1
  • 1
  • 1
    1) Create a new image and display it in a `JLabel`. 2) `IOException("Unsupported image format");` It does not seem like an `IOException` to me. Perhaps `IllegalArgumentException` would be more appropriate. – Andrew Thompson Dec 25 '13 at 06:02
  • could you please show me the working if possible. Thank you. – user1912520 Dec 25 '13 at 06:04
  • *"show me the working"* 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). – Andrew Thompson Dec 25 '13 at 06:06

0 Answers0