RAW images ... help needed..

H

hussainak

Hi, i ve got a raw image to be displayed, i ve used the program below
to generate the raw image...

Code:
import javax.swing.*;
import java.io.*;

public class Rawtest{

public Rawtest(){

int array[];
RandomAccessFile newfile;

array = new int[256];
try{
newfile = new RandomAccessFile("c:\\grey.raw", "rw");
newfile.seek(newfile.length());

for(int i=0; i<array.length; i++)
{
array[i] = i;
//System.out.println(array[i]);

for(int j=0; j<256; j++)
newfile.writeByte(array[i]);
}
}

catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Exception
Raised",JOptionPane.INFORMATION_MESSAGE);
}

}

public static void main(String args[]){

new Rawtest();
}
}

To display this image i m using this program..........

[CODE]

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.image.*;

public class RawDisp extends Applet {

int pictureWidth = 256, pictureHeight = 256;
int pictureArray[] = new int[pictureWidth*pictureHeight];
int data[] = new int[256*256];


/** Creates a new instance of RawDisp */
public void createPicture() {

try{
FileInputStream inp = new FileInputStream("c:\\grey.raw");

int k = 0;
for (int i=0; i<pictureWidth; i++){
for (int j=0; j<pictureHeight; j++) {
for(int h=0; h<data.length; h++){
data[h] = inp.read();

Color c = new Color(data[h],data[h],data[h]);
pictureArray[k++] = c.getRGB();
}
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e,"Exception
Raised",JOptionPane.INFORMATION_MESSAGE);
}
}

public void start() {
createPicture();
}

public void update(Graphics g) {}

Image img;

public void paint(Graphics g) {
img = createImage( new MemoryImageSource(pictureWidth,
pictureHeight, pictureArray, 0, pictureWidth));
g.drawImage(img, 0, 0, this);
}
}

....................

i m unable to display images above 256 x 256 .... pls help me in this
regards....
or if there is some other method to display raw images (e.g. using JAI
API)...i m looking forward for the community to help me.
 
O

Oliver Wong

[snipped code that generates image]
To display this image i m using this program..........
[snipped most of the code]

int pictureWidth = 256, pictureHeight = 256;
int pictureArray[] = new int[pictureWidth*pictureHeight];
int data[] = new int[256*256];
[snipped most of the code]

i m unable to display images above 256 x 256 .... pls help me in this
regards....
or if there is some other method to display raw images (e.g. using JAI
API)...i m looking forward for the community to help me.

Could it be because the dimensions 256x256 are hard coded in the
program? Wouldn't it make more sense to try to infer the dimensions from the
image file, or if that's impossible, allow the user to specify the desired
dimensions?

- Oliver
 
H

hussainak

thanx for taking out time to reply..... pls try this program on ur JVM
and increase the images dim and lemme know
 
O

Oliver Wong

thanx for taking out time to reply..... pls try this program on ur JVM
and increase the images dim and lemme know

Well...

I'd rather not...

And at any rate, you never even specify what the program is supposed to
do, so even if I did run it, I'd never know if it was doing what you
intended or not.

- Oliver
 
H

hussainak

Oliver said:
Well...

I'd rather not...

And at any rate, you never even specify what the program is supposed to
do, so even if I did run it, I'd never know if it was doing what you
intended or not.

- Oliver

ummm...ok....my first program generates a raw image file (u can view it
using PhotoShop) .... i ve written the second program to display the
raw format file ... so that i need not open the file in PhotoShop to
see it....but i ve a problem, i cannot view files larger than 256 x 256
:(
 
O

Oliver Wong

ummm...ok....my first program generates a raw image file (u can view it
using PhotoShop) .... i ve written the second program to display the
raw format file ... so that i need not open the file in PhotoShop to
see it....but i ve a problem, i cannot view files larger than 256 x 256
:(

Okay, well I can tell you right now that your program doesn't do what
you just described above, even if the file is "smaller than or equal to"
256x256.

Your "Rawtest" program actually generates an image consisting of 256
intensity levels. This could be a 1x256 image, or a 2x128 image, or a 4x64
image, or a 8x32 image, or a 16x16 image, etc. But it would never describe a
256x256 image. A 256x256 resolution image would contain 65536 intensity
levels.

Your "RawDisp" applet always displays a 256x256 image, regardless of the
dimensions of the file you feed it.

- Oliver
 
R

Roedy Green

i m unable to display images above 256 x 256

you have hard coded those constants in. By any chance did you forget
to change one of them, and of course the size of the applet itself?

Try using a

static final int MAX_PIXEL_WIDTH = 256;
 
H

hussainak

Oliver said:
Okay, well I can tell you right now that your program doesn't do what
you just described above, even if the file is "smaller than or equal to"
256x256.

Your "Rawtest" program actually generates an image consisting of 256
intensity levels. This could be a 1x256 image, or a 2x128 image, or a 4x64
image, or a 8x32 image, or a 16x16 image, etc. But it would never describe a
256x256 image. A 256x256 resolution image would contain 65536 intensity
levels.

Your "RawDisp" applet always displays a 256x256 image, regardless of the
dimensions of the file you feed it.

- Oliver


yes...exactly.....there my problem lies ... so how do i go abt it? how
should that be solved...anybody here having hands on expirience with
JAI(Java Advanced Imaging) API?

pls help me if you do..... i just need a small example to start with
JAI ....
 
O

Oliver Wong

yes...exactly.....there my problem lies ... so how do i go abt it? how
should that be solved...anybody here having hands on expirience with
JAI(Java Advanced Imaging) API?

pls help me if you do..... i just need a small example to start with
JAI ....

The problem is not with JAI. Your second program should already be
drawing something to screen; the problem is what it's drawing is NOT the
contents of the file on the disk. You need to rethink the logic in your
for-loops.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top