Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:18:22+00:00 2026-06-01T18:18:22+00:00

i am trying to load a .TIF formatted image to add into Jlist and

  • 0

i am trying to load a .TIF formatted image to add into Jlist and display it into frame.
Here is My code what i tried, here though the image is loaded my frame still looks empty and doesn’t showing anything.
please correct my code or suggest me that what should be the change i have to make display my .TIF image.

import javax.media.jai.PlanarImage;
import com.sun.media.jai.codec.ByteArraySeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.SeekableStream;
import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.awt.Image;
import java.awt.image.RenderedImage;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JList;

public class ImageViewer {
  static Image load(byte[] data) throws Exception {
    Image image = null;
    SeekableStream stream = new ByteArraySeekableStream(data);
    String[] names = ImageCodec.getDecoderNames(stream);
    ImageDecoder dec =
            ImageCodec.createImageDecoder(names[0], stream, null);
    RenderedImage im = dec.decodeAsRenderedImage();
    image = PlanarImage.wrapRenderedImage(im).getAsBufferedImage();
    return image;
}



public static void main(String[] args) throws Exception {
    String path;

    DefaultListModel listModel = new DefaultListModel();
    JFrame frame = new JFrame("Split Pain");
    frame.setSize(700, 500);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    path ="C:/Documents and Settings/Administrator/My Documents/My Pictures/tiff Images/CCITT_1.TIF";
    FileInputStream in = new FileInputStream(path);
    FileChannel channel = in.getChannel();
    ByteBuffer buffer = ByteBuffer.allocate((int) channel.size());
    channel.read(buffer);
    Image image = load(buffer.array());
    Image imageScaled =image.getScaledInstance(500, -1, Image.SCALE_SMOOTH);
    listModel.addElement(new ImageIcon(imageScaled));
    final JList list = new JList(listModel);
    frame.add(list);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:18:23+00:00Added an answer on June 1, 2026 at 6:18 pm

    PlanarImage image = JAI.create(“fileload”, “C:\JAVA\mahes_24_m\09-11-1988\mdr16.tiff”);
    using this syntax u can load tiff image.
    BufferedImage bi = image.getAsBufferedImage();
    add this bi to ListModel and give this ListModel to JList, and add JList to JFrame.
    but first u have to download JAI API to use PlanerImage Class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to load a image at runtime in WPF using the following code
I'm actually trying load image based on its screen size. Code seems to be
I am trying load settings.php?id=5 by accessing xml/5/settings.xml here is the code but its
Im trying to load an image from my webserver and display it as an
I'm trying to load a very large image (about 16000x7000 pixel) into a Material,
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
Trying to load content into a div, then on click load the previous content
Trying to load a small .txt file into mysql but get all my data
trying to load in a bunch of images into a list from a directory...my
I trying to load and save setting with this code but when I closing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.