01.
public
static
Bitmap loadBitmap(String url) {
02.
bitmap =
null
;
03.
InputStream in =
null
;
04.
BufferedOutputStream out =
null
;
05.
06.
try
{
07.
BitmapFactory.Options options =
new
BitmapFactory.Options();
08.
options.inJustDecodeBounds =
true
;
09.
BitmapFactory.decodeStream(
new
URL(url).openStream(),
null
,options);
10.
11.
options.inSampleSize = calculateInSampleSize(options,
80
,
80
);
12.
options.inJustDecodeBounds =
false
;
13.
bitmap = BitmapFactory.decodeStream(
new
URL(url).openStream(),
null
,options);
14.
15.
}
catch
(IOException e) {
16.
Log.e(TAG,
"Could not load Bitmap from: "
+ url);
17.
}
finally
{
18.
closeStream(in);
19.
closeStream(out);
20.
}
21.
22.
return
bitmap;
23.
}
24.
25.
public
static
int
calculateInSampleSize(BitmapFactory.Options options,
26.
int
reqWidth,
int
reqHeight) {
27.
28.
final
int
height = options.outHeight;
29.
final
int
width = options.outWidth;
30.
int
inSampleSize =
1
;
31.
32.
if
(height > reqHeight || width > reqWidth) {
33.
if
(width > height) {
34.
inSampleSize = Math.round((
float
) height / (
float
) reqHeight);
35.
}
else
{
36.
inSampleSize = Math.round((
float
) width / (
float
) reqWidth);
37.
}
38.
}
39.
return
inSampleSize;
40.
}