Hi, I am working on an app that displays photos which are downloaded from Flickr. I obtain a Bitmap object from a byte array, which in turn is read from the relevant Flickr URL, as follows:
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); The problem is that the resulting bitmap is pixelated and I can't figure out why. To demonstrate, here is an example of a picture created via BitmapFactory.decodeByteArray versus the original picture obtained directly from the relevant Flickr URL: http://homepages.inf.ed.ac.uk/s0677975/bad.jpg http://homepages.inf.ed.ac.uk/s0677975/good.jpg Look e.g. at the clouds in the top-left corner to see the difference. Can anybody give me a hint as to why this is happening? Below are some additional details. The byte array is obtained as follows; this is based on code from the Photostream app by Romain Guy: InputStream in = new BufferedInputStream(url.openStream(), IO_BUFFER_SIZE); final ByteArrayOutputStream dataStream = new ByteArrayOutputStream(); out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE); copy(in, out); out.flush(); final byte[] data = dataStream.toByteArray(); Note that the more direct approach using e.g. BitmapFactory.decodeStream() does not work; see e.g. the following discussion for details: http://markmail.org/message/m2m3cpkh6ggrvj43#query:BitmapFactory.decodeStream%20vs%20BitmapFactory.decodeByteArray+page:1+mid:ebetxxb3tkngpe7s+state:results Here is the code I used for writing the bitmap to the JPG file linked to above, with no compression: String filename = "test" ; ContentValues values = new ContentValues(); values.put(Images.Media.TITLE, filename); values.put(Images.Media.DATE_ADDED, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = mCtx.getContentResolver().insert (Images.Media.EXTERNAL_CONTENT_URI, values); try { OutputStream outStream = mCtx.getContentResolver().openOutputStream (uri); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.flush(); outStream.close(); } catch (FileNotFoundException e) {} catch (IOException e) {} Any help on this matter would be greatly appreciated. Thanks and best regards, Michael. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en