将下载的com.google.api.services.drive.model.File转换为Bitmap或Uri

时间:2015-12-23 10:33:10

标签: android bitmap google-drive-api

我正在从谷歌硬盘下载一些图像。之后,我想在我的Android应用程序中显示它们,但我无法弄清楚如何将此文件类型转换为位图或任何替代类型,以便我可以在我的应用程序中显示这些图像。这是下载的代码文件。如果有人知道答案,请帮帮我。

 com.google.api.services.drive.model.File file = service.files().get("file path").execute();
//how to converet this file into bitmap or Uri

1 个答案:

答案 0 :(得分:-1)

实际上,您不必将这些文件类型转换为位图,您必须从file.getDownloadUrl()中获取google驱动器文件中的图像,然后将其转换为位图。

File file = service.files().get(files[i]).execute();

HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())).execute();
InputStream is = resp.getContent();
BufferedInputStream bufferedInputStream = new BufferedInputStream(is);

Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);