Knightley
asked on
Send a image using streamconnection.
i have captured a image like:
BufferedImage image = new Robot().createScreenCaptur e(new Rectangle(0,0,400,400));
and would like to send it with DataOutputStream to send it and then then receive it
on my mobile phone (midp) with DataIutputStream.
Since midp could read png format image file. I wonder if there is a way to compress
my BufferedImage to png format before i send it. And then read it on my phone???
thanx in advance
BufferedImage image = new Robot().createScreenCaptur
and would like to send it with DataOutputStream to send it and then then receive it
on my mobile phone (midp) with DataIutputStream.
Since midp could read png format image file. I wonder if there is a way to compress
my BufferedImage to png format before i send it. And then read it on my phone???
thanx in advance
Sorry that should have been
javax.imageio.ImageIO.writ e(buffered Image, "PNG", out);
javax.imageio.ImageIO.writ
ASKER
I am using the following code to send data through my bluetooth device:
OR_conn = (StreamConnection) Connector.open(OR_conn_str ing);
OR_output = new DataOutputStream(new BufferedOutputStream(OR_co nn.openOut putStream( )));
OR_output.writeInt() etc.
How should i integrate your code into mine???
And could you also give me some code about receiving the png data with DataInputStream
thanx.
OR_conn = (StreamConnection) Connector.open(OR_conn_str
OR_output = new DataOutputStream(new BufferedOutputStream(OR_co
OR_output.writeInt() etc.
How should i integrate your code into mine???
And could you also give me some code about receiving the png data with DataInputStream
thanx.
The problem is that is don't do J2ME as i think i've said before, although if you can point me to online docs for the api you're using it's possible that i could help anyway, but not otherwise
ASKER
Thanx very much for your offer, CEHJ. Really appreciate it. But i think and hope you
do not need to read any doc.
I have checked in j2me lib after reading your first anwser.
>>javax.imageio.ImageIO.wr ite(buffer edImage, "PNG", out);
Obviously, javax.imageio.ImageIO is also supported in MIDP.
Since i use DataStreamOutput/Iput to send the data
>>OR_conn = (StreamConnection) Connector.open(OR_conn_str ing);
>>OR_output = new DataOutputStream(new BufferedOutputStream(OR_co nn.openOut putStream( )));
What i am trying to do is:
1. write BufferedImage into PNG format. [javax.imageio.ImageIO.wri te(buffere dImage, "PNG", out);]
2. send it with DataOutputStream;
....
3. receive with DataInputStream;
4. Decode Input with javax.imageio.ImageIO.read to BufferedImage again.
5. Do something on my mobile phone... ...
I think step 1-4 are not J2ME programming, though step 3 and 4 are executed
on my phone, but they are just standard java coding.
So i hope you could help me. Or am i missing something?
thanx again.
do not need to read any doc.
I have checked in j2me lib after reading your first anwser.
>>javax.imageio.ImageIO.wr
Obviously, javax.imageio.ImageIO is also supported in MIDP.
Since i use DataStreamOutput/Iput to send the data
>>OR_conn = (StreamConnection) Connector.open(OR_conn_str
>>OR_output = new DataOutputStream(new BufferedOutputStream(OR_co
What i am trying to do is:
1. write BufferedImage into PNG format. [javax.imageio.ImageIO.wri
2. send it with DataOutputStream;
....
3. receive with DataInputStream;
4. Decode Input with javax.imageio.ImageIO.read
5. Do something on my mobile phone... ...
I think step 1-4 are not J2ME programming, though step 3 and 4 are executed
on my phone, but they are just standard java coding.
So i hope you could help me. Or am i missing something?
thanx again.
Well 1&2 and 3&4 can be collapsed into one operation. If you've got a DataOutputStream, you can let 'out' stand for that
ASKER
you mean like that:
javax.imageio.ImageIO.writ e(buffered Image, "PNG", OR_output);
and what code do i need for reading the stream on my phone?
javax.imageio.ImageIO.writ
and what code do i need for reading the stream on my phone?
>> you mean like that:
Yes. If you're not sending any other data, you can get rid of the DataOutputStream and just use the BufferedOutputStream
>>and what code do i need for reading the stream on my phone?
BufferedImage bi = javax.imageio.ImageIO.read (in);
(if it can use ImageIO)
Yes. If you're not sending any other data, you can get rid of the DataOutputStream and just use the BufferedOutputStream
>>and what code do i need for reading the stream on my phone?
BufferedImage bi = javax.imageio.ImageIO.read
(if it can use ImageIO)
ASKER
ohhh sorry, i was wrong, midp does not support ImageIO.
But it could read a "PNG" byteArray and render it.
So with:
javax.imageio.ImageIO.writ e(buffered Image, "PNG", OR_output);
am i sending a byte Array???
But it could read a "PNG" byteArray and render it.
So with:
javax.imageio.ImageIO.writ
am i sending a byte Array???
ASKER
ohhh sorry, i was wrong, midp does not support ImageIO.
But it could read a "PNG" byteArray and render it.
So i could turn a image or bufferedimage into png and send it
using:
output.writeByte():
By using:
javax.imageio.ImageIO.writ e(buffered Image, "PNG", OR_output);
am i sending a byte Array???
But it could read a "PNG" byteArray and render it.
So i could turn a image or bufferedimage into png and send it
using:
output.writeByte():
By using:
javax.imageio.ImageIO.writ
am i sending a byte Array???
>>am i sending a byte Array???
Yes, encoded in PNG format
Yes, encoded in PNG format
ASKER
Could i simply using
for(int i=0; i<ByteArray_length; i++){
input.readByte()
}
to read this byte array?
But how could i know how long this Byte array is?
for(int i=0; i<ByteArray_length; i++){
input.readByte()
}
to read this byte array?
But how could i know how long this Byte array is?
You'd read the stream to eof - perhaps into a ByteArrayOutputStream
ASKER
could i somehow use
javax.imageio.ImageIO.writ e(buffered Image, "PNG", ...
to save the the png FISRT into a ByteArray, and then
send it per DataOutputStream.writeByte ()?
Then it is easier to read it as in my last post?
javax.imageio.ImageIO.writ
to save the the png FISRT into a ByteArray, and then
send it per DataOutputStream.writeByte
Then it is easier to read it as in my last post?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
works out, thanx very much, CEHJ
:-)
javax.image.ImageIO.write(