I encountered a similar error when trying to decode a buffered input stream from a web server using BitmapFactory. We identified this as a bug that will be fixed in the next version. Here is a workaround you can use:
Bitmap bitmap = null; InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new URL("http://blah.com/foo/bar.jpg").openStream(), IO_BUFFER_SIZE); final ByteArrayOutputStream dataStream = new ByteArrayOutputStream(); out = new BufferedOutputStream(dataStream, 4 * 1024); copy(in, out); out.flush(); final byte[] data = dataStream.toByteArray(); bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); } catch (IOException e) { android.util.Log.e("IO", "Could not load buddy icon: " + this, e); } finally { closeStream(in); closeStream(out); } And to make it work you will need the following two methods: /** * Copy the content of the input stream into the output stream, using a temporary * byte array buffer whose size is defined by [EMAIL PROTECTED] #IO_BUFFER_SIZE}. * * @param in The input stream to copy from. * @param out The output stream to copy to. * * @throws IOException If any error occurs during the copy. */ private static void copy(InputStream in, OutputStream out) throws IOException { byte[] b = new byte[4 * 1024]; int read; while ((read = in.read(b)) != -1) { out.write(b, 0, read); } } /** * Closes the specified stream. * * @param stream The stream to close. */ private static void closeStream(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { android.util.Log.e("IO", "Could not close stream", e); } } } On Thu, Oct 2, 2008 at 8:26 AM, Nemat <[EMAIL PROTECTED]> wrote: > > I have applied the way given in link.I think the problem is in > displaying the image?? > Do u know the reason behind this JPEG error??? > > On Oct 1, 7:07 pm, Mark Hansen <[EMAIL PROTECTED]> wrote: >> I followed this short tutorial a while back for downloading an image >> via http, maybe it can point you in the right direction... >> >> http://www.anddev.org/gallery_with_remote_images-t769.html >> >> On Oct 1, 6:51 am, Nemat <[EMAIL PROTECTED]> wrote: >> >> > Hi, >> >> > I have to download an image from server.But I got an error "D/skia >> > ( 197): xxxxxxxxxxx jpeg error 53 Not a JPEG file: starts with 0x%02x >> > 0x%02x" >> >> > I have to perform two continues Http connection.First is used to get >> > server response and second to get image from the server.First task is >> > performed correctly but while downloading image I got the given >> > eror.So the problem in getting image from server. >> >> > My code is: >> > Code: >> >> > public ImageView getView(String myImageURL) { >> > Log.i("TAG","downloadFile000000000000000000"+myImageURL); >> > ImageView i = new ImageView(this); >> >> > try { >> > /* Open a new URL and get the InputStream to load data >> > from it. */ >> > URL aURL = new URL(myImageURL); >> > URLConnection conn = aURL.openConnection(); >> >> > Log.i("TAG","downloadFile1111111111111111111"+myImageURL); >> > conn.connect(); >> > InputStream is = conn.getInputStream(); >> >> > Log.i("TAG","downloadFile2222222222222222222222"+is.read()); >> > /* Buffered is always good for a performance plus. */ >> > BufferedInputStream bis = new BufferedInputStream(is); >> >> > Log.i("TAG","downloadFile33333333333333333333="+bis.read()); >> > /* Decode url-data to a bitmap. */ >> > // Bitmap bm = BitmapFactory.decodeStream(bis); >> > Bitmap bm = BitmapFactory.decodeStream(is); >> > // >> > Log.i("TAG","downloadFile4444444444444444444"+bm.getHeight()); >> > // bis.close(); >> > is.close(); >> > /* Apply the Bitmap to the ImageView that will be >> > returned. */ >> > i.setImageBitmap(bm); >> > Log.i("TAG","downloadFile555555555555555555555"); >> > } catch (IOException e) { >> > Log.i("TAG","downloadFile666666666666666666666666"); >> > Log.e("DEBUGTAG", "Remtoe Image Exception", e); >> > } >> >> > /* Image should be scaled as width/height are set. */ >> > // i.setScaleType(ImageView.ScaleType.FIT_CENTER); >> > /* Set the Width/Height of the ImageView. */ >> >> > return i; >> > } >> >> > This code works fine when I performed this task alone in another >> > project. > > > -- Romain Guy www.curious-creature.org --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---