2013-03-25 76 views
1

我想在一秒内显示约30张照片,因此它们将显示为视频。在Android中显示连续图像

我在while(TRUE)循环中使用Android ImageView,但ImageView没有像我期望的那样变化。

的ImageView的改变图片的大约每秒,所以不知道是否有另一种方式来

表现出我的照片?

这些照片是从使用UDP照相机传送,并且我首先需要在缓冲液中和

比显示存储。

上述部分导致ImageView延迟。代码

部分是这样的

public void receiveVideoRawData() throws IOException{ 
     socket_video = new DatagramSocket(); 
     byte[] buf_rcv = new byte[153600]; 
     DatagramPacket rawData = new DatagramPacket(buf_rcv, buf_rcv.length); 
     Bitmap image = null; 
     socket_video.receive(rawData);//receive a raw data 
     image = readMyRawData.readUINT_RGBImage(buf_rcv);//decode the raw data 
     ByteArrayOutputStream blob = new ByteArrayOutputStream(); 
     Bitmap pBitmap = image ; 
     pBitmap.compress(Bitmap.CompressFormat.JPEG, 1, blob); 
     byte[] bitmapdata = blob.toByteArray(); 
     ardrone_Frame = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata.length); 
     } 

显示部分

Thread thread=new Thread (new Runnable() { 
    Message message; 
    String obj="run"; 
    int i; 
    long start; 
    @Override 
    public void run() { 
     // TODO Auto-generated method stub 
     Log.e("///enter thread ","THREAD"); 
    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) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 
} 

}); 
public Handler handler = new Handler(){ 
    @Override 
    public void handleMessage(Message msg) { 
      super.handleMessage(msg); 
      String MsgString = (String)msg.obj; 
      if (MsgString.equals("run")) 
      {   Log.e("///enter handler ","HANDLER");           
          Toast.makeText(ArDroneMain.this,"save image ",Toast.LENGTH_SHORT).show(); 
          //Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+ "/ArdroneVideo.jpg"); 
          myImageView.setImageBitmap(ardrone_Frame); ///Show the image  
          Toast.makeText(ArDroneMain.this,"show image",Toast.LENGTH_SHORT).show(); 
      } 

    } 
}; 
+0

代码为这些图像做ü要动态加载图像?或者它存储在res? – 2013-03-25 09:39:47

+0

设置每个图像后,需要重新绘制'ImageView'。你能展示你目前使用的代码吗? – Tigger 2013-03-25 09:50:43

回答

4

你可以做到这一点,我使它成为一个动画。 为您的动画制作图像并保存在png格式的文件夹中。 动画下面

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> 
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" /> 
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" /> 
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" /> 
</animation-list> 

然后

AnimationDrawable rocketAnimation; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image); 
    rocketImage.setBackgroundResource(R.drawable.rocket_thrust); 
    rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); 
} 

public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
    rocketAnimation.start(); 
    return true; 
    } 
    return super.onTouchEvent(event); 
} 
0

您可以随时使用FFmpeg的创建图像的视频,还可以使用一个TimerTask

delay=1000/totalImages; 

myTimer = new Timer(); 
     myTimer.schedule(new TimerTask() {   
      @Override 
      public void run() { 

          if(count==imgArr.length) 
           cancel(); 

          imageView.setImageResource(imgArr[count]); 
          count++;  

      } 

     }, 0, delay);