안드로이드 개발 질문/답변
(글 수 45,052)
Thread cThread = new Thread(){
public void run(){
try {
DatagramSocket datasocket = new DatagramSocket(7778);
while(true){
img(datasocket);
}
} catch (Exception e) {
error.setText("udp error");
}
}
};
cThread.start();
public void img(final DatagramSocket datasocket){
handler.post(new Runnable(){
public void run(){
try{
byte[] buf = new byte[120*160*2];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
File file = new File("/sdcard/tmp.jpg");
datasocket.receive(packet);
if(file.exists()){
file.delete();
}
file.createNewFile();
FileOutputStream fout = new FileOutputStream(file);
fout.write(packet.getData());
fout.close();
tmp = BitmapFactory.decodeFile("/sdcard/tmp.jpg");
Image();
tmp=null;
}catch(Exception e){
error.setText("save error");
}
}
});
}
public void Image(){
runOnUiThread(new Runnable(){
public void run(){
imView.setImageBitmap(tmp);
}
});
}
udp 로 보내진 jpg를 저장을 하고 그 그림을 화면에 출력하는건데.. 지금 소스대로 하면 화면에 한번은 출력이 가능합니다.
그런데 반복적으로 작업을 할려고 반복문을 넣어주면 그 반복문이 실행이 끝까지 다 되고나서야 마지막에 레이아웃이 한꺼번에 다 나오네요 ㅠㅠ
계속 jpg를 덮어쓰고 화면에 출력하고 덮어 쓰고 출력하고 해야되는데 말이죠 ㅠㅠ
반복적으로 이미지만 새로 불러오는 방법이 없을까요?
이미지 부분문 계속 바뀌면 끝인데..
public void run(){
try {
DatagramSocket datasocket = new DatagramSocket(7778);
while(true){
img(datasocket);
}
} catch (Exception e) {
error.setText("udp error");
}
}
};
cThread.start();
public void img(final DatagramSocket datasocket){
handler.post(new Runnable(){
public void run(){
try{
byte[] buf = new byte[120*160*2];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
File file = new File("/sdcard/tmp.jpg");
datasocket.receive(packet);
if(file.exists()){
file.delete();
}
file.createNewFile();
FileOutputStream fout = new FileOutputStream(file);
fout.write(packet.getData());
fout.close();
tmp = BitmapFactory.decodeFile("/sdcard/tmp.jpg");
Image();
tmp=null;
}catch(Exception e){
error.setText("save error");
}
}
});
}
public void Image(){
runOnUiThread(new Runnable(){
public void run(){
imView.setImageBitmap(tmp);
}
});
}
udp 로 보내진 jpg를 저장을 하고 그 그림을 화면에 출력하는건데.. 지금 소스대로 하면 화면에 한번은 출력이 가능합니다.
그런데 반복적으로 작업을 할려고 반복문을 넣어주면 그 반복문이 실행이 끝까지 다 되고나서야 마지막에 레이아웃이 한꺼번에 다 나오네요 ㅠㅠ
계속 jpg를 덮어쓰고 화면에 출력하고 덮어 쓰고 출력하고 해야되는데 말이죠 ㅠㅠ
반복적으로 이미지만 새로 불러오는 방법이 없을까요?
이미지 부분문 계속 바뀌면 끝인데..