如何将缩略图从 Box android-content-sdk 转换为位图?
How to convert a thumbnail from Box android-content-sdk to a bitmap?
如本期所见,Box android-content-sdk 中有两种方法 return 一个请求:
How to get thumbnails with box android-content-sdk (notV2)
第一个的目标是本地文件,另一个是 OutputStram 对象。
在我的例子中,我会在 AsyncTask 中得到一个位图,如下所示:
Bitmap bm = BitmapFactory.decodeStream(InputStream is)
所以找不到 Box android-sdk-content 的解决方案,我尝试将 outputStream 转换为 InputStream,如下所示:(此方法在 AsynckTask 中调用)
protected Bitmap getThumbBox(final String id, final BoxApiFile apiFile) throws IOException {
Bitmap bitmap = null;
PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
new Thread(
new Runnable(){
public void run(){
//put your code that writes data to the outputstream here.
BoxRequestsFile.DownloadThumbnail downloadThumbnail = apiFile.getDownloadThumbnailRequest(out,id);
}
}
).start();
//data can be read from the pipedInputStream here.
bitmap = BitmapFactory.decodeStream(in);
return bitmap;
}
据此:
http://io-tools.sourceforge.net/easystream/outputstream_to_inputstream/Pipes.html
但没有成功。
有任何想法吗?
谢谢。
以下是我如何设法将缩略图转换为位图:
protected Bitmap getThumbBox(final String id, final BoxSession session) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BoxDownload req = null;
try {
req = new BoxApiFile(session).getDownloadThumbnailRequest(bos, id).setMinSize(256).send();
} catch (BoxException e) {
e.printStackTrace();
}
byte[] byteArr = bos.toByteArray();
Bitmap bm = BitmapFactory.decodeByteArray(byteArr, 0, byteArr.length);
return bm;
}
如本期所见,Box android-content-sdk 中有两种方法 return 一个请求: How to get thumbnails with box android-content-sdk (notV2)
第一个的目标是本地文件,另一个是 OutputStram 对象。
在我的例子中,我会在 AsyncTask 中得到一个位图,如下所示:
Bitmap bm = BitmapFactory.decodeStream(InputStream is)
所以找不到 Box android-sdk-content 的解决方案,我尝试将 outputStream 转换为 InputStream,如下所示:(此方法在 AsynckTask 中调用)
protected Bitmap getThumbBox(final String id, final BoxApiFile apiFile) throws IOException {
Bitmap bitmap = null;
PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
new Thread(
new Runnable(){
public void run(){
//put your code that writes data to the outputstream here.
BoxRequestsFile.DownloadThumbnail downloadThumbnail = apiFile.getDownloadThumbnailRequest(out,id);
}
}
).start();
//data can be read from the pipedInputStream here.
bitmap = BitmapFactory.decodeStream(in);
return bitmap;
}
据此: http://io-tools.sourceforge.net/easystream/outputstream_to_inputstream/Pipes.html
但没有成功。 有任何想法吗? 谢谢。
以下是我如何设法将缩略图转换为位图:
protected Bitmap getThumbBox(final String id, final BoxSession session) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BoxDownload req = null;
try {
req = new BoxApiFile(session).getDownloadThumbnailRequest(bos, id).setMinSize(256).send();
} catch (BoxException e) {
e.printStackTrace();
}
byte[] byteArr = bos.toByteArray();
Bitmap bm = BitmapFactory.decodeByteArray(byteArr, 0, byteArr.length);
return bm;
}