请教高手,为什么我截不了图?
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
public class SnapperMidlet extends MIDlet implements CommandListener{
private Display display;
private Form mainForm;
private Command exitCommand,cameraCommand;
private Command backCommand,captureCommand;
private Player player;
private VideoControl videoControl;
public SnapperMidlet(){
exitCommand=new Command("Exit",Command.EXIT,0);
cameraCommand=new Command("Play",Command.SCREEN,0);
backCommand=new Command("Back",Command.BACK,0);
captureCommand=new Command("Scrap",Command.SCREEN,0);
mainForm=new Form("Scrap");
mainForm.addCommand(exitCommand);
String supports=System.getProperty("video.snapshot.encodings");
if(supports!=null&&supports.length()>0){
mainForm.append("support");
mainForm.addCommand(cameraCommand);
}else
mainForm.append("no support");
mainForm.setCommandListener(this);
}
public void startApp(){
display=Display.getDisplay(this);
display.setCurrent(mainForm);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
mainForm=null;
try{
defplayer();
}catch(MediaException e){}
}
public void commandAction(Command c,Displayable s){
if(c.getCommandType()==Command.EXIT){
destroyApp(false);
notifyDestroyed();
}
if(c==cameraCommand){
Thread t=new Thread(){
public void run(){
showCamera();
}
};
t.start();
}
if(c==backCommand)
display.setCurrent(mainForm);
if(c==captureCommand){
Thread t=new Thread(){
public void run(){
capture();
}
};
t.start();
}
}
private void showCamera(){
Form f=new Form("Video");
f.addCommand(backCommand);
f.addCommand(captureCommand);
f.setCommandListener(this);
try{
InputStream ins=getClass().getResourceAsStream("/R600Cinema.mpg");
Player p=Manager.createPlayer(ins,"video/mpeg");
p.realize();
VideoControl vidc;
Item videoItem=null;
if((vidc=(VideoControl)p.getControl("VideoControl"))!=null){
videoItem=(Item)vidc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null);
}
p.start();
f.append(videoItem);
display.setCurrent(f);
}catch(MediaException me){
}catch(IOException ioe){
}
}
public void capture(){
try{
byte[] raw=videoControl.getSnapshot(null);//用System.out.println检测,问题出现在这里,但参数为null的话就是说格式为png
Image image=Image.createImage(raw,0,raw.length);
Image thumb=createThumbnail(image);
if(mainForm.size()>0&&mainForm.get(0) instanceof StringItem){
mainForm.delete(0);
}
mainForm.append(thumb);
display.setCurrent(mainForm);
player.close();
player=null;
videoControl=null;
}catch(MediaException e){ }
}
private Image createThumbnail(Image image){
int sourceWidth=image.getWidth();
int sourceHeight=image.getHeight();
int thumbWidth=64;
int thumbHeight=-1;
if(thumbHeight==-1)
thumbHeight=thumbWidth*sourceHeight/sourceWidth;
Image thumb=Image.createImage(thumbWidth,thumbHeight);
Graphics g=thumb.getGraphics();
for(int y=0;y<thumbHeight;y++)
for(int x=0;x<thumbWidth;x++){
g.setClip(x,y,1,1);
int dx=x*sourceWidth/thumbWidth;
int dy=y*sourceHeight/thumbHeight;
g.drawImage(image,x-dx,y-dy,Graphics.LEFT|Graphics.TOP);
}
Image immutableThumb=Image.createImage(thumb);
return immutableThumb;
}
void defplayer() throws MediaException{
if(player!=null){
if(player.getState()==Player.STARTED){
player.stop();
}
if(player.getState()==Player.PREFETCHED){
player.deallocate();
}
if(player.getState()==Player.REALIZED||player.getState()==Player.UNREALIZED){
player.close();
}
}
player=null;
}
}
我已经把源代码完完整整编辑上去了,编译通过,也可以运行,但截图的时候出现NoPointerException异常,究竟怎么解决啊?