image processing - Android: BitmapFactory.decodeByteArray gives pixelated bitmap -
I am working on an Android app that displays photos downloaded from Flickr. I get a bitmap object from a byte array, which in turn is read from the corresponding flickr url, as follows:
Bitmap Factory. Option = new bitmapfile Option (); OptInDither = true; Opt.inPreferredConfig = Bitmap Config.Argb_8888; Bitmap bitmap = bitmapfender Databet more (data, 0, data. Length, opt);
I then draw a bitmap to the canvas on the ondroid system of a visual object:
paint paint = new paint (paint.nti_al_ass_flag | paintFILTER_BITMAP_FLAG); Canvas.draw bitmap (bitmap, 0, 0, paint);
The problem is that the resulting picture is pixelated and I do not understand why; I have not made any difference to fortune and paint objects, there is no luck in it. The difference between the picture displayed in my app and the picture of the original URL is shown by the following:
See for example
Note that JPEG images that are loaded with project resources and displayed in the same manner are displayed properly, that is, no pixelation occurs.
Can someone give me an indication as to why this is happening?
To expand slightly, the byte array has been received from Flickr; This is based on the code of the Photostream app by Roman:
In InputStream = new BufferedInputStream (url.openstream (), IO_BUFFER_SIZE); Last BitReon OutputStream Datastream = New Bytereanputstream (); Out = New BufferedOutputStream (Data Stream, IO_BUFFER_SIZE); Copy (in, out); Out.flush (); Last Byte [] Data = Datastream To Batteryre ();
PS: I have Android The developer has also posted a version of this question on Google Groups.
Thank you very much for your suggestion - I am really surprised now! As I suggested and I found that the image obtained from the downloaded directly byte array is actually pixelated, however, it is downloaded from the same URL which is not pixelized when it is accessed on my computer. Here's the Flickr URL:
Even strangers, when I run the same app in the simulator instead of my phone (an HTC Hero), then any pixels Does not happen
How is this possible on earth?
Below is a code used to load a bitmap from a URL - this is based on the Photostream app by Roman Gay, and will be suggested to write raw byte array to file in it Includes:
Bitmap Load PhotoBitmap (URL URL) {bitmap bitmap = null; InputStream Inn = Null; Buffer output stream = exit; {FileOutputStream fos = Try New FileOutputStream ("/ sdcard / photo-tmp.jpg"); BufferedOutputStream bfs = New BufferedOutputStream (fos); In = new buffer inputstream (url.openstream (), IO_BUFFER_SIZE); Last BitReon OutputStream Datastream = New Bytereanputstream (); Out = New BufferedOutputStream (Data Stream, IO_BUFFER_SIZE); Copy (in, out); Out.flush (); Last Byte [] Data = Datastream To Batteryre (); Bfs.write (data, 0, data.length); Bfs.flush (); Bitmapfile Option opt = new bitmap feature. Option (); Bitmap = bitmapfireterDisadAbabyteArray (data, 0, data.line, op); } Grip (IOException e) {android.util.Log.e (LOG_TAG, "Photo could not be loaded:" + it, e); } Finally {closeStream (in); CloseStream (outside) passstream (BFS); } Return Bitmap; } Private static zero copy (InputStream, OutputStream Out) throws IOException {byte [] B = new byte [IO_BUFFER_SIZE]; Read int; While ((read = in.read (b))! = -1) {out.write (b, 0, read); }} Private Static Zero Empty Stream (Offable Stream) {if (stream! = Null) {try {stream.close (); } Hold (IOException e) {android.util.Log.e (LOG_TAG, "stream could not be closed", e); }}}
Am I getting mad here? Best, Michael.
Write raw bytes brought in / sdcard / tmp from the URL Jpg
, And see on your PC.
JPEG images are compressed in 8x8 (or 16x16) tiles. As a 'pixelation' you describe it, in fact in these tiles, it is suggesting that the 'bad' image is JPEG which is more aggressively compressed than the other.
So I hope the real problem is that the image being downloaded is a very low quality version, eg for a thumbnailing / preview usage-cases.
Comments
Post a Comment