?
Solved

Bit Map Image

Posted on 2003-03-15
12
Medium Priority
?
191 Views
Last Modified: 2010-03-31
I have a file which contains the bit map for an image. Is there a facility in Java to display that image i.e. setting the pixels based on that bit map?
0
Comment
Question by:jc31415
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8142744
Image i = Toolkit.getDefaultToolkit().createImage("your.bmp");
0
 

Author Comment

by:jc31415
ID: 8142824
My image is not a "BMP" image. It just a series of 1's and 0's that represent the value of each pixel.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8142831
How are these 1s and 0s stored?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:jc31415
ID: 8142880
That shouldn't matter. I just want to read them and set the apporpriat pixel. I have often done this in C++, where there is a function SetPixel.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8142890
It does matter, because different files are interpreted in different ways. What have you got - a 'binary' file?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8142941
You need to look at BufferedImage (JDK > 1.3) or MemoryImageSource (JDK > 1.0 )

have a look here for an example:

    int iw = im.getWidth( parent ) ;
    int ih = im.getHeight( parent ) ;

    int[] imagearr = new int[ iw * ih ] ;

    PixelGrabber pg = new PixelGrabber( im, 0, 0, iw, ih, imagearr, 0, iw );
    try
    {
      pg.grabPixels();
    }
    catch (InterruptedException e)
    {
    }
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8142945
NOT THAT!!

*hits keyboard*

This:

http://www.cafeaulait.org/course/week9/24.html
0
 

Author Comment

by:jc31415
ID: 8143096
That's what I wanted, except for one thing. It is for an applet, and everything I found on a web search was for an applet. Can't an image be created for a program? If not I'll just have to use the applet version.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8143110
Toolkit.getDefaultToolkit().createImage()
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8143113
Like CEHJ Said:

Image i = Toolkit.getDefaultToolkit().createImage("your.bmp");

:-)
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 8143119
Here's an example of an image being created in an application:


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

public class DynImage {

  public static void main(String[] args){
    JFrame f = new JFrame();
    f.getContentPane().add(new DynImagePanel());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 300);
    f.setVisible(true);
  }

}

class DynImagePanel extends JPanel {
  BufferedImage image;
  int width;
  int height;

  public DynImagePanel() {
    super();
    // Create an image and paint it on the component
    width = 200;
    height = 200;
    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    WritableRaster raster = image.getRaster();
    // Make a light blue colour
    int[] colour = { 0xcc, 0xcc, 0xff };
    for(int i = 0;i < width;i++) {
      for(int j = 0;j < height;j++) {
        raster.setPixel(i, j, colour);
      }
    }
    setPreferredSize(new Dimension(width, height));
  }

  public void paintComponent(Graphics g) {
    g.drawImage(image, 0, 0, width, height, null);
  }


}
0
 

Author Comment

by:jc31415
ID: 8143170
That's exactly what I wanted!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question