마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 (클라이언트) - 자바 (서버) 이미지 소켓 송수신 질문입니다.

0 추천
Socket socket = null;
		InputStream inputStream = null;
		BufferedInputStream bufStream = null;
		
		byte[] readBytes = new byte[1024];
		ByteArrayInputStream bais = new ByteArrayInputStream(readBytes);
		
		@Override
		public void run() {
			
			 try {
				socket = new Socket(ip, port);
				inputStream = socket.getInputStream();
				bufStream = new BufferedInputStream(inputStream);
				
				OutputStream out = null;
				
				int len = 0;
			
				while ((len = bufStream.read(readBytes)) != -1) {
					
					bais.read(readBytes);
					System.out.println(new String(readBytes,0,readBytes.length));
				}
				
				File filecacheItem = new File("/sdcard/data/nbpl.kiyoung.sensor_control/Change_Image.jpg");
								
				filecacheItem.createNewFile();
				out = new FileOutputStream(filecacheItem);
				
				Bitmap bitmap = BitmapFactory.decodeByteArray(readBytes, 0, readBytes.length);
				bitmap.compress(CompressFormat.JPEG, 100, out);
				
				out.close();
				
			} catch (Exception e) {
				e.printStackTrace();

			} finally {
				try {
					
					bufStream.close();
					inputStream.close();
					socket.close();

				} catch (IOException e) {
                                   e.printStackTrace();
				}
			}

안드로이드 (클라이언트) - 자바 (서버) 이렇게 두고, 소켓 통신을 이용해서

이미지 파일을 송수신 하는 어플을 구현중에 있습니다. 

자바 서버에서 보낸 이미지 파일을 안드로이드 클라이언트에서 소켓 통신으로 받아서 이미지 파일로

저장을 해야 되는데, 안드로이드 부분에서 이미지 변환 쪽이 잘 해결이 되지 않습니다.

자바 서버에서는 Bytearray 형식으로 송신해서 안드로이드 클라이언트로 수신하는 것은 잘 되는 것 같습니다만,

bitmap.compress 이 구문을 이용해서 비트맵 변환을 시키면 SkImageDecoder::Factory returned null

이런 로그가 계속 나타나면서 이미지 변환이 되지 않습니다.  구글링을 하면서 이것저것 다 해봤는데,

어떻게 수정해야 되는지 막막하여 질문을 드립니다. (소스 코드에 이것저것 시도하다 보니 엉망인점 양해부탁드립니다.)
 

긔영 (120 포인트) 님이 2015년 3월 16일 질문

1개의 답변

0 추천
서버에서 보낸 이미지를 파일로 저장한 후 그것을 decode하면 정상동작할 것 같네요.
익명사용자 님이 2015년 3월 16일 답변
...