-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.java
More file actions
65 lines (53 loc) · 1.57 KB
/
Copy pathImage.java
File metadata and controls
65 lines (53 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package photorainbow;
import java.lang.StringBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.*;
import java.io.*;
public class Image {
private static final Logger log = Logger.getLogger(Image.class.getName());
public String imageUrl;
private Bitmap bitmap;
public Image(String imgUrl) {
this.imageUrl = imgUrl;
download();
}
public Image() {
}
public void download() {
try {
URL iurl = new URL(imageUrl);
URLConnection yc = iurl.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(yc.getInputStream()));
StringBuffer imageData = new StringBuffer();
while ((inputLine = reader.readLine()) != null) {
imageData.append(inputLine);
}
bitmap = new Bitmap(imageData);
Bitmap scaledImage = new Bitmap(bitmap, new Size(100, 100));
bitmap = scaledImage;
}
catch (Exception e) {
log.log(Level.ERROR, e.printStackTrace());
}
finally {
try {
if (reader != null) reader.close();
} catch (IOException ex) {
log.log(Level.ERROR, ex.printStackTrace());
}
}
}
public String getUrl() {
return this.imageUrl;
}
public void setUrl(String url) {
this.url = url;
}
public Bitmap getBitmap() {
return this.bitmap;
}
public void setBitmap(Bitmap data) {
this.bitmap = data;
}
}