URL-адрес URL-адреса, который можно использовать в Java,
复制代码代码如下:
public static Bitmap loadImageFromUrl(String url, int sc) {
URL-адрес м;
Входной поток я = ноль;
BufferedInputStream бис = ноль;
ByteArrayOutputStream out = null;
байт isBuffer[] = новый байт[1024];
если (url == ноль)
вернуть ноль;
пытаться {
м = новый URL-адрес (URL);
я = (InputStream) m.getContent();
бис = новый BufferedInputStream (я, 1024 * 4);
выход = новый ByteArrayOutputStream();
интервал Лен = 0;
while ((len = bis.read(isBuffer)) != -1) {
out.write(isBuffer, 0, len);
}
выход.закрыть();
бис.закрыть();
} catch (MalformedURLException e1) {
e1.printStackTrace();
вернуть ноль;
} catch (IOException e) {
е.printStackTrace();
}
если (выход == ноль)
вернуть ноль;
данные byte[] = out.toByteArray();
Опции BitmapFactory.Options = новый BitmapFactory.Options();
options.inJustDecodeBounds = правда;
BitmapFactory.decodeByteArray(данные, 0, data.length, параметры);
options.inJustDecodeBounds = ложь;
int be = (int) (options.outHeight / (float) sc);
если (быть <= 0) {
быть = 1;
} иначе, если (быть > 3) {
быть = 3;
}
options.inSampleSize = быть;
Растровое изображение bmp = ноль;
пытаться {
bmp = BitmapFactory.decodeByteArray(данные, 0, data.length, параметры); // 返回缩略图
} catch (OutOfMemoryError e) {
// TODO: обработать исключение
Система.gc();
БМП = ноль;
}
вернуть БМП;
}