안드로이드 개발 질문/답변
(글 수 45,052)
임베디드 시스템에서 전송받은 비트맵이미지를 화면에 뿌려주려고 하는데 잘 안되네요 ㅜㅜ
160 x 120 그림크기로 헤더까지 다 붙은 bmp 파일을 전송하였고
안드로이드에서 받을때
InputStream in=socket.getInputStream();
byte buf[]=new byte[57654];
int readBytes=0;
int totalBytes=57654;
int totalRead=0;
for(; totalRead < totalBytes; totalRead += readBytes) {
readBytes = in.read(arrbuf, totalRead, totalBytes - totalRead);
}
위와 같이 수신하였습니다.
그런후에
ByteArrayInputStream in = new ByteArrayInputStream(arrbuf);
Bitmap bitmap = BitmapFactory.decodeStream(in);
((ImageView)findViewById(R.id.ImageView01)).setImageBitmap(bitmap);
이렇게 해서 imageview에 뿌려줄려고 하는데
Bitmap bitmap = BitmapFactory.decodeStream(in);
여기서 bitmap에 byte가 잘 안들어가는것 같습니다.
BitmapFactory.decodestream 로 변환할때 byte array에는 jpeg이나 png 와 같은 파일이 들어가 있어야 하는것인가요???
어떻게 읽어온 BMP파일 데이터를 어떻게 화면에 뿌려줘야하는지 모르겠습니다. ㅜㅜ 제발 좀 도와주십시오 ㅜㅜ
160 x 120 그림크기로 헤더까지 다 붙은 bmp 파일을 전송하였고
안드로이드에서 받을때
InputStream in=socket.getInputStream();
byte buf[]=new byte[57654];
int readBytes=0;
int totalBytes=57654;
int totalRead=0;
for(; totalRead < totalBytes; totalRead += readBytes) {
readBytes = in.read(arrbuf, totalRead, totalBytes - totalRead);
}
위와 같이 수신하였습니다.
그런후에
ByteArrayInputStream in = new ByteArrayInputStream(arrbuf);
Bitmap bitmap = BitmapFactory.decodeStream(in);
((ImageView)findViewById(R.id.ImageView01)).setImageBitmap(bitmap);
이렇게 해서 imageview에 뿌려줄려고 하는데
Bitmap bitmap = BitmapFactory.decodeStream(in);
여기서 bitmap에 byte가 잘 안들어가는것 같습니다.
BitmapFactory.decodestream 로 변환할때 byte array에는 jpeg이나 png 와 같은 파일이 들어가 있어야 하는것인가요???
어떻게 읽어온 BMP파일 데이터를 어떻게 화면에 뿌려줘야하는지 모르겠습니다. ㅜㅜ 제발 좀 도와주십시오 ㅜㅜ
소켓의 inputStream에서 바로 생성해보세요.
Drawable d = Drawable.createFromStream(socket.getInputStream(), "");