Has anyone an idea how to get a BufferedInputStream to a byte[] so that I can make a Bitmap of it?
That's my Stream:
BufferedInputStream stream = new BufferedInputStream(socket.getInputStream());
And that's my byte[]:
byte[] bytes;
uhm... the read() method of the BufferedInputStream will give you the byte[] you need.
For getting a Bitmap, use the BitmapFactory.decodeStream() method and pass in your BufferedInputStream as a parameter. Good to go ! :)
Bitmap bitmap = BitmapFactory.decodeStream(stream)BitmapFactory.Options.new Handel(Looper.getMainLooper()).post(runnable);BufferedInputStream stream = new BufferedInputStream(s.getInputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int theByte;
while((theByte = stream.read()) != -1) baos.write(theByte);
Then:
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
byte[] imageByteArray = bytes;
Bitmap bitmap = BitmapFactory.decodeByteArray(imageByteArray, 0, imageByteArray.length, opt);
imageView.setImageBitmap(bitmap);
BitmapFactory.decodeStream() because so that I can make a Bitmap of it :pdecodeStream() and let Android do the magic ;) It is overloaded. :)