Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebImageViewer "Fixing 'skia decoder->decode returned false' error on Android OS 2.3" #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/main/java/com/github/droidfu/imageloader/ImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
package com.github.droidfu.imageloader;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
Expand Down Expand Up @@ -290,20 +293,33 @@ protected byte[] retrieveImageData() throws IOException {
if (fileSize < 0) {
return null;
}
byte[] imageData = new byte[fileSize];

// download the file
// download the file using method specified on:
// http://stackoverflow.com/questions/4339082/android-decoder-decode-returned-false-for-bitmap-download/5039288#5039288
Log.d(LOG_TAG, "fetching image " + imageUrl + " (" + fileSize + ")");
BufferedInputStream istream = new BufferedInputStream(connection.getInputStream());
int bytesRead = 0;
int offset = 0;
while (bytesRead != -1 && offset < fileSize) {
bytesRead = istream.read(imageData, offset, fileSize - offset);
offset += bytesRead;
InputStream i = null;
BufferedInputStream bis = null;
ByteArrayOutputStream out = null;
byte[] imageData = null;
try {
i = (InputStream) connection.getContent();
bis = new BufferedInputStream(i, 1024 * 8);
out = new ByteArrayOutputStream();
int len = 0;
byte[] buffer = new byte[1024];
while ((len = bis.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.close();
bis.close();
imageData = out.toByteArray();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

// clean up
istream.close();

// clean up connection
connection.disconnect();

return imageData;
Expand Down