我从我的设备接收到连续的 UDP 数据(RAW 图像)。解码它并使用位图显示
我的 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);
}