KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joshy > html > ImageUtil


1 package org.joshy.html;
2
3 import org.joshy.u;
4 import javax.swing.ImageIcon JavaDoc;
5 import java.awt.Image JavaDoc;
6 import java.net.URL JavaDoc;
7 import java.net.MalformedURLException JavaDoc;
8
9 public class ImageUtil {
10     public static Image JavaDoc loadImage(Context c, String JavaDoc src) throws MalformedURLException JavaDoc {
11         Image JavaDoc img = null;
12         if(src.startsWith("http")) {
13             img = new ImageIcon JavaDoc(new URL JavaDoc(src)).getImage();
14         } else {
15             //u.p("src = " + src);
16
URL JavaDoc base = c.getBaseURL();
17             if(base != null) {
18                 URL JavaDoc image_url = new URL JavaDoc(base,src);
19                 //u.p("image url = " + image_url);
20
img = new ImageIcon JavaDoc(image_url).getImage();
21             } else {
22                 img = new ImageIcon JavaDoc(src).getImage();
23             }
24         }
25         if(img != null && img.getWidth(null) == -1) {
26             return null;
27         }
28         return img;
29     }
30 }
31
Popular Tags