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