2012-07-06 55 views
1

我試圖在服務器端爲android mobile.so構建RDP應用程序,我發送帶有機器人類的png圖像,但在客戶端,我無法讀取該消息並在我的android設備。從流中讀取PNG文件

我使用下面的代碼來讀取JPEG文件體數據,我能夠顯示這些圖像

InputStream in = sock.getInputStream(); 
while(true) 
{ 
byte[] bytes = new byte[1024*1024]; 
int count = 0; 
do 
{ 
count+= in.read(bytes,count,bytes.length-count); 
} 
while(!(count>4&&bytes[count-2]==(byte)-1 && bytes[count-1]==(byte)-39)); 

} 

任何一個可以幫助我如何讀取PNG文件出InputStream的。

回答

1

試試這個

BufferedInputStream in = new BufferedInputStream(sock.getInputStream()); 
BufferedImage image = ImageIO.read(in);