I need some help.
If somebody knows something about, please tell me to my email.
Thank you.
> I need to do this operation (image --> byte[]) and dont know how to do it.
>
> I need some help.
>
> If somebody knows something about, please tell me to my email.
>
> Thank you.
Hi Josom,
Try this tutorial:
http://developer.java.sun.com/developer/onlineTraining/javaai/jai/index.html
Regards,
Erwin
java.lang.NoClassDefFoundError: javax/media/jai/PlanarImage
at FrontPageDemoApplet.init(FrontPageDemoApplet.java:14)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
And the subprogram doesn´t initialize so I can´t see what is inside.
Please request if there is something I am done wrong.
Thank you.
"Erwin Moller" <erwin@_no_spam_dexus.nl> escribió en el mensaje
news:3eb8d27e$0$49109$e4fe...@news.xs4all.nl...
> Im trying to get in the page you said to me but I have a problem or the
> page has a problem:
>
> java.lang.NoClassDefFoundError: javax/media/jai/PlanarImage
> at FrontPageDemoApplet.init(FrontPageDemoApplet.java:14)
> at sun.applet.AppletPanel.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
> And the subprogram doesnt initialize so I cant see what is inside.
>
> Please request if there is something I am done wrong.
>
> Thank you.
>
>
Hi Josom,
Sorry for that: You are right, I have the same problem.
They screwed their own tutorial up somehow...
Okay, because I wasted you time, here is some real codesnippet I use to make
it up to you:
(please check your API on javax.imageio for details)
import javax.imageio.*;
import javax.imageio.stream.*;
import java.util.*;
import java.io.*;
import java.awt.image.*;
import java.awt.Graphics2D;
import java.awt.*;
// where to write the file?
File f = new File(strPath);
// get an outputstream
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
// trick to get png-helper
Iterator writers = ImageIO.getImageWritersByFormatName("png");
ImageWriter writer = (ImageWriter)writers.next();
// Once an ImageWriter has been obtained, its destination must be set to an
ImageOutputStream:
writer.setOutput(ios);
// Finally, the image may be written to the output stream:
BufferedImage bi = new
BufferedImage(ImageWidth,ImageHeight,BufferedImage.TYPE_INT_RGB);
// get a handle to the Graphics-object for drawing
G = bi.createGraphics();
// make the image completely blue
G.setColor(Color.blue);
G.fillRect(0, 0, ImageWidth, ImageHeight);
// and write it to the filehandle:
writer.write(bi);
// dispose your graphicsobject because Java-gc has problems doing that on
its own.
G.dispose();
I am not sure if sun screwed up.
Maybe you (and I) didn't follow their instructions on the page before
entering the tutorial.
:-/
Anyway, good luck.
Sorry, I am really confused today and send you the wrong code.
It is code to generate a png, not to create an array of bytes out of an
image.
I think I should get some sleep now.
Sorry to be such a *$##@!*
:-(
Regards,
Erwin
This is what you should do, but you have to figure out some details
yourself:
File theImageFile = null;
FileInputStream FIS = null;
BufferedInputStream BIS = null;
ServletOutputStream SOS = null;
try {
// Open an inpustream
theImageFile = new File("usr/home/etc...path to your image");
FIS = new FileInputStream(theImageFile);
BIS = new BufferedInputStream(FIS);
// now loop:
int aByte = BIS.read();
while (aByte != -1) {
aByte=BIS.read();
// Now josom, use this aByte to store it somewhere.
}
BIS.close();
FIS.close();
SOS.close();
} catch (Exception any)
{
// do something useful.
}
Regards,
Erwin
PS: going home now. :-)
ok
If you have some real code I will be gratefull!!!
Thank you in advance.
"Erwin Moller" <erwin@_no_spam_dexus.nl> escribió en el mensaje
news:3eb92609$0$49103$e4fe...@news.xs4all.nl...
in which format do you want to have the image returned in bytes? png, jpg or
raw?
What I want is convert an object java.awt.image into a byte[] to later use
another method that I have.
So I don´t know if is important if the original image is .jpg or .bmp or
.tiff ...
I think if close the cases into an image monochrome the problem will be
easier although later I have to do this with color images.
The method I have to use is:
dcmNueva.set(DDict.dPixelData,pixels); //Insert the pixel data into
Dicom file.
where pixels is byte[]. (This method is from an libraries about
Dicom, so maybe you won´t know; I think is no important to know about it)
I hope this information will be good.
Thank you.
"Erwin Moller" <erwin@_no_spam_dexus.nl> escribió en el mensaje
news:3eb92779$0$49101$e4fe...@news.xs4all.nl...
> Im sorry but I think this is a confusion, but maybe is better to do it
> this way.
>
> What I want is convert an object java.awt.image into a byte[] to later use
> another method that I have.
>
> So I dont know if is important if the original image is .jpg or .bmp or
> .tiff ...
>
> I think if close the cases into an image monochrome the problem will be
> easier although later I have to do this with color images.
>
> The method I have to use is:
>
> dcmNueva.set(DDict.dPixelData,pixels); //Insert the pixel data into
> Dicom file.
>
> where pixels is byte[]. (This method is from an libraries about
> Dicom, so maybe you wont know; I think is no important to know about it)
>
> I hope this information will be good.
>
> Thank you.
>
Hi Josom,
Let's have a beer someday. :-)
Okay, I see what you mean now.
But now it get complicated. :-(
the byte[] array you are refering to, is not defined yet .
It is defined of course, but you and I do not know how.
It depends on the used COLORMODEL what the bytes mean.
I cannot help you with clear code, only point you in the right direction.
Note: My knowledge on Image-producing on byte-level is based on the 'old'
awt, and nowadays we have the Graphics2D. It is very well possible that
new, more convenient classes and methods exists in tthere. I do not know.
Please note that a java.awt.Image is just an abstract notion of a Image.
What is the colordepth?
Was it in greyscale?
etc.
So this has to be defined before the byte-stream has any meaning.
'Old' approach:
You have to create a Image (You did already I guess) and implement logic for
an ImageProducer and a ImageConsumer.
ImageObserver
It is important you study the following classes to get a grib on the issue:
(look in java.awt.Image)
Image
ImageObserver
ImageProducer
ImageConsumer
The method imageUpdate(Image img, int infoflags, int x, int y, int width,
int height) is called a few times in an ImageObserver untill the Image is
'ready' (=produced).
Good luck with it.
Maybe is is wise to try the 'new' Graphics2D first and look for more
convenient classes and methods.
Keep me informed!
Regards,
Erwin
public byte[] intarray2bytearray(image) {
byte[] pixels = new byte[image.getWidth(this) * image.getHeight(this)];
int[] pix = new int[image.getWidth(this) * image.getHeight(this)];
PixelGrabber pg = new PixelGrabber(image,0,0,
image.getWidth(this),image.getHeight(this), pix, 0, image.getWidth(this));
try {
pg.grabPixels();
} catch (InterruptedException e) {return pixels; }
for(int arrayPointer=0;arrayPointer<pix.length;arrayPointer++){
pixels[arrayPointer] = new Integer(pix[arrayPointer]).byteValue();
}
return pixels;
}
Let us know how it works for you
"José Mª" <gv...@elai.upm.es> wrote in message news:3eb8...@news.upm.es...