For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2005 > Collect input stream as jpg file.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Collect input stream as jpg file.
Boki

2005-10-25, 3:57 am

Hi All,
My last step, collect the input steam ( data ) to a jpg file,
could you please help to finish it ? thank you very much!

//--------------------
....
public InputStream in;
private StreamConnection con = null;
in = con.openInputStream();
....
//------------------
....
// collect input data to jpg file


try{

int bytesToRead = in.available();
if (bytesToRead > 0) {
// Initialize buffer
byte[] byteBuffer = new byte[bytesToRead];
// Read bytes
int nbrOfBytesRead = in.read(byteBuffer);
String str = new String(byteBuffer);
}
}
------------------


Boki

2005-10-25, 3:57 am

For this line:
in.read(byteBuffer);

It seems that the everytime I got data of inputStream, the in.read(xxx) will
overwrite my array data, and it seems that I can't use pointer
byteBuffer[pData++], right?

Could you please help?
Thank you very much!

Best regards,
Boki.

"Boki" <bokiteam@ms21.hinet.net> 级糶秎ン穝籇:djkk0c$s05$1@netnews.hinet.net...
> Hi All,
> My last step, collect the input steam ( data ) to a jpg file,
> could you please help to finish it ? thank you very much!
>
> //--------------------
> ...
> public InputStream in;
> private StreamConnection con = null;
> in = con.openInputStream();
> ...
> //------------------
> ...
> // collect input data to jpg file
>
>
> try{
>
> int bytesToRead = in.available();
> if (bytesToRead > 0) {
> // Initialize buffer
> byte[] byteBuffer = new byte[bytesToRead];
> // Read bytes
> int nbrOfBytesRead = in.read(byteBuffer);
> String str = new String(byteBuffer);
> }
> }
> ------------------
>
>



Boki

2005-10-25, 3:57 am

any better way ?
--------------
try{
int count_jpg=0;
int bytesToRead = in.available();
if (bytesToRead > 0) {
// Initialize buffer
byte[] byteBuffer = new byte[bytesToRead];
// Read bytes
int nbrOfBytesRead = in.read(byteBuffer);

GUI.ggg+=bytesToRead;
gui.repaint();

for (count_jpg=0;count_jpg<bytesToRead;count_jpg++)
imageData[GUI.ggg+count_jpg]=byteBuffer[count_jpg];
}
}
"Boki" <bokiteam@ms21.hinet.net> 级糶秎ン穝籇:djkkdr$bjk$1@netnews.hinet.net...
> For this line:
> in.read(byteBuffer);
>
> It seems that the everytime I got data of inputStream, the in.read(xxx)
> will overwrite my array data, and it seems that I can't use pointer
> byteBuffer[pData++], right?
>
> Could you please help?
> Thank you very much!
>
> Best regards,
> Boki.
>
> "Boki" <bokiteam@ms21.hinet.net> 级糶秎ン穝籇:djkk0c$s05$1@netnews.hinet.net...
>
>



Boki

2005-10-25, 3:57 am

whatever, I have done the protype, I am trying the performance :D

btw, how to capture the webcam jpg data on PC ??

do I have to consider USB driver ?

or How can I get the JPG image directly?

Thank you very mcuh!

:D

Best regards,
Boki.


"Boki" <bokiteam@ms21.hinet.net> 级糶秎ン穝籇:djklhg$h94$1@netnews.hinet.net...
> any better way ?
> --------------
> try{
> int count_jpg=0;
> int bytesToRead = in.available();
> if (bytesToRead > 0) {
> // Initialize buffer
> byte[] byteBuffer = new byte[bytesToRead];
> // Read bytes
> int nbrOfBytesRead = in.read(byteBuffer);
>
> GUI.ggg+=bytesToRead;
> gui.repaint();
>
> for (count_jpg=0;count_jpg<bytesToRead;count_jpg++)
> imageData[GUI.ggg+count_jpg]=byteBuffer[count_jpg];
> }
> }
> "Boki" <bokiteam@ms21.hinet.net> 级糶秎ン穝籇:djkkdr$bjk$1@netnews.hinet.net...
>
>



Roedy Green

2005-10-25, 3:57 am

On Tue, 25 Oct 2005 14:40:12 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

> String str = new String(byteBuffer);


You don't want a string. This has nothing to do with human-readable
text. Have a look at the ImageIO class.

see http://mindprod.com/jgloss/imageio.html

It will let you read from a file on an InputStream.

If you have to make this work on an old JVM you can do it with:

Image image = toolkit.createImage( rawImage );
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green

2005-10-25, 3:57 am

On Tue, 25 Oct 2005 14:47:23 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

>It seems that the everytime I got data of inputStream, the in.read(xxx) will
>overwrite my array data, and it seems that I can't use pointer
>byteBuffer[pData++], right?


see http://mindprod.com/jgloss/readblocking.html
for how to do that. However, you don't need to. ImageIO will do it for
you.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green

2005-10-25, 3:57 am

On Tue, 25 Oct 2005 15:52:05 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

>btw, how to capture the webcam jpg data on PC ??


import javax.imageio.ImageIO;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.ControllerAdapter;
import javax.media.ControllerClosedEvent;
import javax.media.ControllerListener;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.media.StartEvent;
import javax.media.StopEvent;
import javax.media.control.FormatControl;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.RGBFormat;
import javax.media.format.VideoFormat;
import javax.media.format.YUVFormat;
import javax.media.util.BufferToImage;

I would tackle something easier for now.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Boki

2005-10-25, 7:02 pm

Dear Green,
any example :D?

Best regards,
Boki.

"Roedy Green" <my_email_is_posted_on_my_website@munged.invalid>
???????:92srl11ao04a8p71j0kuijr2i0migad0cq@4ax.com...
> On Tue, 25 Oct 2005 15:52:05 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote, quoted or indirectly quoted someone who said :
>
>
> import javax.imageio.ImageIO;
> import javax.media.CaptureDeviceInfo;
> import javax.media.CaptureDeviceManager;
> import javax.media.ControllerAdapter;
> import javax.media.ControllerClosedEvent;
> import javax.media.ControllerListener;
> import javax.media.Format;
> import javax.media.Manager;
> import javax.media.MediaLocator;
> import javax.media.Player;
> import javax.media.RealizeCompleteEvent;
> import javax.media.StartEvent;
> import javax.media.StopEvent;
> import javax.media.control.FormatControl;
> import javax.media.control.FrameGrabbingControl;
> import javax.media.format.RGBFormat;
> import javax.media.format.VideoFormat;
> import javax.media.format.YUVFormat;
> import javax.media.util.BufferToImage;
>
> I would tackle something easier for now.
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Again taking new Java programming contracts.



Boki

2005-10-25, 7:02 pm

This is a good example, does it possible to receive unknow length, and auto
stop when time out?

I can't image that code stop running ~~ @@ ( that makes me can't implement
time out when I polling data... )


"Roedy Green" <my_email_is_posted_on_my_website@munged.invalid>
???????:11srl11auchtjfj56dsihe5p2ln1dsp615@4ax.com...
> On Tue, 25 Oct 2005 14:47:23 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote, quoted or indirectly quoted someone who said :
>
>
> see http://mindprod.com/jgloss/readblocking.html
> for how to do that. However, you don't need to. ImageIO will do it for
> you.
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Again taking new Java programming contracts.



Boki

2005-10-25, 7:02 pm

You are right, I don't need that.

I don't know J2ME can use imageIO or not, I will try tomorrow :D thanks a
lot.


"Roedy Green" <my_email_is_posted_on_my_website@munged.invalid>
???????:umrrl1171shu02g90qdmliotv2ungr7hk8@4ax.com...
> On Tue, 25 Oct 2005 14:40:12 +0800, "Boki" <bokiteam@ms21.hinet.net>
> wrote, quoted or indirectly quoted someone who said :
>
>
> You don't want a string. This has nothing to do with human-readable
> text. Have a look at the ImageIO class.
>
> see http://mindprod.com/jgloss/imageio.html
>
> It will let you read from a file on an InputStream.
>
> If you have to make this work on an old JVM you can do it with:
>
> Image image = toolkit.createImage( rawImage );
> --
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Again taking new Java programming contracts.



Roedy Green

2005-10-26, 4:01 am

On Wed, 26 Oct 2005 00:44:33 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

>Dear Green,
> any example :D?


Sorry,. I am not up for it. It is very tricky.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2005-10-26, 4:01 am

On Wed, 26 Oct 2005 00:46:06 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

>This is a good example, does it possible to receive unknow length, and auto
>stop when time out?


that would give you random crap and be infuriatingly slow.

For sockets you put a length on the front.

For HTTP, if it won't give you a length, see
http://mindprod.com/jgloss/readblocking.html
http://mindprod.com/jgloss/readeverything.html
http://mindprod.com/applets/fileio.html (HTTP GET)

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green

2005-10-26, 4:01 am

On Wed, 26 Oct 2005 00:46:54 +0800, "Boki" <bokiteam@ms21.hinet.net>
wrote, quoted or indirectly quoted someone who said :

>I don't know J2ME can use imageIO or not, I will try tomorrow :D thanks a
>lot.

It will need some sort of method for taking a JPG image as a stream
of a byte[].
You know how to convert byte[] to stream and back, right? If not see
http://mindprod.com/applets/fileio.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com