반응형

wxpython에서 사용했던 방법인데..


똑같이 구현되었는데(?) 좀 느리다..


하지만 깜박이지 않고 잘 동작한다. 



import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import android.app.Fragment; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; public class DFragment extends Fragment { ImageView image; MyAsyncTask mTask; Bitmap bitmap = null; private SendMassgeHandler mMainHandler = null; private CountThread mCountThread = null; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View v = inflater.inflate(R.layout.dfragment, container, false); return v; } public void onDestroy () { super.onDestroy(); mCountThread.stopThread(); Log.w("", "end"); } @Override public void onStart () { super.onStart(); image = (ImageView) getActivity().findViewById(R.id.image); mMainHandler = new SendMassgeHandler(); mCountThread = new CountThread(); mCountThread.start(); } class SendMassgeHandler extends Handler { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if ( bitmap !=null) image.setImageBitmap(bitmap); } }; ⁄⁄ Thread 클래스 class CountThread extends Thread implements Runnable { private boolean isPlay = false; public CountThread() { isPlay = true; } public void isThreadState(boolean isPlay) { this.isPlay = isPlay; } public void stopThread() { isPlay = !isPlay; } @Override public void run() { super.run(); int i = 0; while (isPlay) { URL url = null; try { url = new URL("http:⁄⁄3cam25984.365home.org:82⁄snapshot.cgi?user=admin&pwd=&resolution=32"); } catch (MalformedURLException e) { ⁄⁄ TODO Auto-generated catch block e.printStackTrace(); } try { bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream()); } catch (IOException e) { ⁄⁄ TODO Auto-generated catch block e.printStackTrace(); } mMainHandler.sendEmptyMessageDelayed(0, 50); } } } }


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts