4
我從設備接收到連續的UDP數據(RAW圖像)。解碼和使用位圖顯示在android中顯示圖像使用位圖的延遲
我的Android手機,所以它會看起來像一個視頻。問題是,幀不連續顯示
。框架變化約。每2〜3秒但我想在1/30中逐幀顯示。
下面是我的代碼
public class ArDroneMain extends Activity {
Bitmap image = null;
public ImageView myImageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
animationDrawable = new AnimationDrawable();
myImageView = (ImageView)findViewById(R.id.imageView);
thread.start();
}
}
Thread thread=new Thread (new Runnable() {
Message message;
String obj="run";
@Override
public void run() {
while(true){
try {
Log.e("enter_video_thread","enter_video_thread");
receiveVideoRawData();
Log.e("///receiveVideoRawData ","receiveVideoRawData");
message = handler.obtainMessage(1,obj);
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public Handler handler = new Handler(){
@SuppressLint("NewApi")
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String MsgString = (String)msg.obj;
if (MsgString.equals("run"))
{
Drawable ardrone_Frame_Drawable =newBitmapDrawable(getResources(),image);
animationDrawable.addFrame(ardrone_Frame_Drawable,100);
myImageView.setBackground(animationDrawable);
}
}
};
public void sendTriggerCommand() throws IOException{
byte [] ip_bytes = new byte[] {(byte)192,(byte)168,(byte)1,(byte)1};//Drone address
byte[] buf_snd = {0x01, 0x00, 0x00, 0x00};//trigger buffer
inet_addr = InetAddress.getByAddress(ip_bytes);
DatagramPacket packet_snd = new DatagramPacket(buf_snd, buf_snd.length, i net_addr, ardrone_video_port);
socket_video.send(packet_snd);
}
public void receiveVideoRawData() throws IOException{
Log.e("enter_receiveVideoRawData()","enter_receiveVideoRawData()");
socket_video = new DatagramSocket();
byte[] buf_rcv = new byte[153600];
DatagramPacket rawData = new DatagramPacket(buf_rcv, buf_rcv.length);
sendTriggerCommand();
Log.e("sendTriggerCommand();","sendTriggerCommand();");
socket_video.receive(rawData);
Log.e("socket_video.receive(rawData);","socket_video.receive(rawData);");
ReadRawFileImage readMyRawData=new ReadRawFileImage();
image = readMyRawData.readUINT_RGBImage(buf_rcv);
}
在您的while循環中嘗試睡眠以逐幀顯示 – 13KZ