Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Collect input stream as jpg file.

Reply
Thread Tools

Collect input stream as jpg file.

 
 
Boki
Guest
Posts: n/a
 
      10-25-2005
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);
}
}
------------------


 
Reply With Quote
 
 
 
 
Boki
Guest
Posts: n/a
 
      10-25-2005
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" <(E-Mail Removed)> 级糶秎ン穝籇:djkk0c$s05$(E-Mail Removed)...
> 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);
> }
> }
> ------------------
>
>



 
Reply With Quote
 
 
 
 
Boki
Guest
Posts: n/a
 
      10-25-2005
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" <(E-Mail Removed)> 级糶秎ン穝籇:djkkdr$bjk$(E-Mail Removed)...
> 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" <(E-Mail Removed)> 级糶秎ン穝籇:djkk0c$s05$(E-Mail Removed)...
>> 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);
>> }
>> }
>> ------------------
>>
>>

>
>



 
Reply With Quote
 
Boki
Guest
Posts: n/a
 
      10-25-2005
whatever, I have done the protype, I am trying the performance

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!



Best regards,
Boki.


"Boki" <(E-Mail Removed)> 级糶秎ン穝籇:djklhg$h94$(E-Mail Removed)...
> 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" <(E-Mail Removed)> 级糶秎ン穝籇:djkkdr$bjk$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> 级糶秎ン穝籇:djkk0c$s05$(E-Mail Removed)...
>>> 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);
>>> }
>>> }
>>> ------------------
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-25-2005
On Tue, 25 Oct 2005 14:40:12 +0800, "Boki" <(E-Mail Removed)>
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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-25-2005
On Tue, 25 Oct 2005 14:47:23 +0800, "Boki" <(E-Mail Removed)>
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.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-25-2005
On Tue, 25 Oct 2005 15:52:05 +0800, "Boki" <(E-Mail Removed)>
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.
 
Reply With Quote
 
Boki
Guest
Posts: n/a
 
      10-25-2005
Dear Green,
any example ?

Best regards,
Boki.

"Roedy Green" <(E-Mail Removed) >
???????:(E-Mail Removed) ...
> On Tue, 25 Oct 2005 15:52:05 +0800, "Boki" <(E-Mail Removed)>
> 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.



 
Reply With Quote
 
Boki
Guest
Posts: n/a
 
      10-25-2005
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" <(E-Mail Removed) >
???????:(E-Mail Removed) ...
> On Tue, 25 Oct 2005 14:47:23 +0800, "Boki" <(E-Mail Removed)>
> 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.



 
Reply With Quote
 
Boki
Guest
Posts: n/a
 
      10-25-2005
You are right, I don't need that.

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


"Roedy Green" <(E-Mail Removed) >
???????:(E-Mail Removed) ...
> On Tue, 25 Oct 2005 14:40:12 +0800, "Boki" <(E-Mail Removed)>
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from Input Stream to Output Stream Kashif Ur Rehman Java 2 05-17-2007 07:50 PM
How to collect the data from input created by document.write() in ASP.NET? BP ASP .Net 2 12-21-2006 04:24 PM
How to collect the data from input created by document.write() in ASP.NET? BP ASP .Net Web Controls 0 12-21-2006 03:22 PM
How to GET multi-word input from a *file* stream as opposed to a *console* stream? sherifffruitfly@gmail.com C++ 9 04-27-2006 04:14 PM
use Excel2000 as web interface to collect user input? Michael ASP General 0 08-11-2005 05:23 PM



Advertisments