Collect input stream as jpg file.

B

Boki

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);
}
}
------------------
 
B

Boki

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.
 
B

Boki

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 said:
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 said:
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);
}
}
 
B

Boki

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 said:
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 said:
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 said:
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);
}
}
 
R

Roedy Green

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 );
 
R

Roedy Green

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.
 
B

Boki

Dear Green,
any example :D?

Best regards,
Boki.

Roedy Green 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.
 
B

Boki

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 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.
 
B

Boki

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.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top