Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmapFactory.decodeStream cannot decode png type from ftp
    primarykey
    data
    text
    <ul> <li>What was my mistake? How I show png from FTP?</li> </ul> <p>I'm newby for android and try to show image from difference connection/source. Then I already show image which load from drawable and HTTP.</p> <p>Now, I'm try to show from FTP, I get message "--- decoder->decode returned false" when I use..<code>BitmapFactory.decodeStream(ins, null, options);</code> </p> <p>Then I found solution..</p> <pre><code>static class FlushedInputStream extends FilterInputStream { public FlushedInputStream(InputStream inputStream) { super(inputStream); } @Override public long skip(long n) throws IOException { long totalBytesSkipped = 0L; while (totalBytesSkipped &lt; n) { long bytesSkipped = in.skip(n - totalBytesSkipped); if (bytesSkipped == 0L) { int b = read(); if (b &lt; 0) { break; // we reached EOF } else { bytesSkipped = 1; // we read one byte } } totalBytesSkipped += bytesSkipped; } return totalBytesSkipped; } } </code></pre> <p>Then it can load/decode file type "Jpeg, jpg", there are show completely.</p> <p>But log cat say "--- decoder->decode returned false" when bitmap load file type "PNG" again.</p> <p>Thank for advice...</p> <pre><code> ImageView bmImage = (ImageView) findViewById(R.id.faceImageView); BitmapFactory.Options bmOptions; bmOptions = new BitmapFactory.Options(); bmOptions.inSampleSize = 1; Bitmap bm = LoadImage(image_URL, bmOptions); bmImage.setImageBitmap(bm); </code></pre> <p>...</p> <pre><code>private Bitmap LoadImage(String URL, BitmapFactory.Options options) { Bitmap bitmap = null; InputStream in = null; FlushedInputStream fIns = null; try { if (isFTP) { in = downloadFile(""); if (remoteFile.toLowerCase().contains(".png")) { fIns = new FlushedInputStream(in); bitmap = BitmapFactory.decodeStream(fIns, null, options); // byte[] bMapArray = new byte[buf.available()]; // buf.read(bMapArray); // bitmap = BitmapFactory.decodeByteArray(bMapArray, 0, // bMapArray.length); } else { fIns = new FlushedInputStream(in); bitmap = BitmapFactory.decodeStream(fIns); } } else { // HTTP in = OpenHttpConnection(URL); fIns = new FlushedInputStream(in); bitmap = BitmapFactory.decodeStream(fIns); } in.close(); } catch (IOException e1) { } return bitmap; } public synchronized InputStream downloadFile(String localfilename) { InputStream inputStream = null; String user = "aaa"; String pass = "8888"; String host = "xxx.xxx.xxx.xxx"; try { FTPClient mFTPClient = new FTPClient(); mFTPClient.connect(host); mFTPClient.login(user, pass); mFTPClient.enterLocalPassiveMode(); mFTPClient.changeWorkingDirectory("/DroidPic"); String[] aa = mFTPClient.listNames(); String strTmp = ""; do { strTmp = aa[(new Random()).nextInt(aa.length)]; } while (remoteFile == strTmp); remoteFile = strTmp; inputStream = mFTPClient.retrieveFileStream(remoteFile); } catch (Exception ex) { Toast.makeText(this, "Err:" + ex.getMessage(), Toast.LENGTH_LONG) .show(); } return inputStream; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload