How to convert BufferedImage?
hi everyone:
I have created a player using cloned dataSource, after the player has been realized I try to convert a grabbed frame to bufferedImage.
Unfortunately, I got Null value for the image. The codes are follow:
public void takeSnapshot(){
FrameGrabbingControl fgc = null;
snapshotDs = dataSource.cloneCamSource();
try{
snapshotPlayer = Manager.createRealizedPlayer(snapshotDs);
if(snapshotPlayer != null)
snapshotPlayer.start();
}catch (IOException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}catch (NoPlayerException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}catch (CannotRealizeException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}
playhelper = new StateHelper(snapshotPlayer);
if(!playhelper.realize(10000)){
JOptionPane.showMessageDialog(this,
"cannot realize snapshotPlayer", "Error", JOptionPane.WARNING_MESSAGE);
return;
}
if( snapshotPlayer != null)
fgc = (FrameGrabbingControl)snapshotPlayer.getControl("javax.media.control.FrameGrabbingControl");
else
System.err.println("Cannot get FrameGrabbingControl");
Buffer bufferFrame = fgc.grabFrame();
System.out.println("bufferFrame :"+bufferFrame);
BufferToImage bufferToImage = new BufferToImage((VideoFormat)bufferFrame.getFormat());
System.out.println("bufferToImage :"+bufferToImage);
BufferedImage image = (BufferedImage)bufferToImage.createImage(bufferFrame);
if(image != null)
System.out.println("Successful convert image :"+image);
else
System.out.println("Fail to convert image :" + image);
}
and I got the ouputs from terminal window:
bufferFrame :javax.media.Buffer@9b87f6
bufferToImage :javax.media.util.BufferToImage@140b8fd
Fail to convert image :null
Does anyone know why the image is Null value? Can someone help me to fix the problem?
Kinds regards.
Lianke
[2347 byte] By [
liankea] at [2007-11-27 10:23:07]

# 2
> why don't you use the code formatting tags?
Sorry, I am posting the codes in code formatting tag again.
hi everyone:
I have created a player using cloned dataSource, after the player has been realized I try to convert a grabbed frame to bufferedImage.
Unfortunately, I got Null value for the image. The codes are follow:
public void takeSnapshot(){
FrameGrabbingControl fgc = null;
snapshotDs = dataSource.cloneCamSource();
try{
snapshotPlayer = Manager.createRealizedPlayer(snapshotDs);
if(snapshotPlayer != null)
snapshotPlayer.start();
}catch (IOException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}catch (NoPlayerException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}catch (CannotRealizeException e) {
JOptionPane.showMessageDialog(this,
"Exception creating snapshotPlayer: " + e.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}
playhelper = new StateHelper(snapshotPlayer);
if(!playhelper.realize(10000)){
JOptionPane.showMessageDialog(this,
"cannot realize snapshotPlayer", "Error", JOptionPane.WARNING_MESSAGE);
return;
}
if( snapshotPlayer != null)
fgc = (FrameGrabbingControl)snapshotPlayer.getControl("javax.media.control.FrameGrabbingControl");
else
System.err.println("Cannot get FrameGrabbingControl");
Buffer bufferFrame = fgc.grabFrame();
System.out.println("bufferFrame :"+bufferFrame);
BufferToImage bufferToImage = new BufferToImage((VideoFormat)bufferFrame.getFormat());
System.out.println("bufferToImage :"+bufferToImage);
BufferedImage image = (BufferedImage)bufferToImage.createImage(bufferFrame);
if(image != null)
System.out.println("Successful convert image :"+image);
else
System.out.println("Fail to convert image :" + image);
}
and I got the ouputs from terminal window:
bufferFrame :javax.media.Buffer@9b87f6
bufferToImage :javax.media.util.BufferToImage@140b8fd
Fail to convert image :null
Does anyone know why the image is Null value? Can someone help me to fix the problem?
Kinds regards.
Lianke