Thank you for your answer !

imgView.setBitmap(bm) is working very well without failure in thred routine
as you described

but I need refreshing of screen with new bitmap image data repeatedly.

In addition to your code, for the purpose of refreshing new image data, I
added infinite loop with while(isStop) operation.


public MyThread extends Thread {
 Handler handler;
 public MyThread() {
   super();
    handler = new Handler();
 }
 public void run() {
   ..
   ...
   handler.post(new Runnable() {
     public void run() {
       while(isStop){
            imgData = getImage();  // imgData receive jpeg image data
            bm = BitmapFactory.decodeByteArray(imgData,0,imgData.length); //
convert jpeg image into bitmap
            imgView.setBitmap(bm);
       }
     }
   });
   ...
 }
}

then this program works with no error.
While loop goes on...
I can have right image data, but display never refresh with new image data.
and program didn't response any kind of input such like a button.




2009/3/3 Streets Of Boston <[email protected]>

>
> imgView.setBitmap can not be called from any other thread than the
> main thread (i.e. thread on which you created your view).
>
> do this instead:
>
> handler.post(new Runnable() {
>  public void run() {
>    imgView.setBitmap(bm);
>  }
> });
>
> The 'handler' can be created by just calling 'new Handler()' on the
> main thread, e.g. when you create your worker-thread.
>
> public MyThread extends Thread {
>  Handler handler;
>  public MyThread() {
>    super();
>     handler = new Handler();
>  }
>  public void run() {
>    ..
>    ...
>    handler.post(new Runnable() {
>      public void run() {
>        imgView.setBitmap(bm);
>      }
>    });
>    ...
>   }
> }
> On Mar 2, 4:47 am, rex <[email protected]> wrote:
> > Hi~
> >
> > I'm trying to periodically change image data in ImageView in the
> > thread routine
> > but when I put this code in the tread routine, program is killed.
> >
> >  imgView.setBitmap(bm);
> >
> > here is my thread code
> > ...
> >
> > private byte[] imgData;
> > private Bitmap bm;
> >
> > new Thread (new Runnable()
> > {
> >     public void run()
> >     {
> >         while(!isStop){
> >                    imgData = getImage();
> >                    bm = BitmapFactory.decodeByteArray(imgData,
> > 0,imgData.length);
> >                    imgView.setBitmap(bm); --> This caused error!!
> >         }
> >      }
> >
> > }).start();
> >
> > ...
> >
> > imgData is receiving jpeg image data from somewhere.
> > Outside thread routine, image data is displayed well.
> >
> > If above is impossible, are there any other ways to periodically image
> > data refreshing on screen ?
> >
> > Thanks!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to