本文整理汇总了Java中net.sf.image4j.codec.ico.ICODecoder.read方法的典型用法代码示例。如果您正苦于以下问题:Java ICODecoder.read方法的具体用法?Java ICODecoder.read怎么用?Java ICODecoder.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.image4j.codec.ico.ICODecoder
的用法示例。
在下文中一共展示了ICODecoder.read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changed
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
@Override
public void changed(ObservableValue<? extends State> observable, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
try {
//Determine the full url
String favIconFullURL = getHostName(webEngine.getLocation()) + "favicon.ico";
//System.out.println(favIconFullURL)
//Create HttpURLConnection
HttpURLConnection httpcon = (HttpURLConnection) new URL(favIconFullURL).openConnection();
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
List<BufferedImage> image = ICODecoder.read(httpcon.getInputStream());
//Set the favicon
facIconImageView.setImage(SwingFXUtils.toFXImage(image.get(0), null));
} catch (Exception ex) {
//ex.printStackTrace()
facIconImageView.setImage(null);
}
}
}
示例2: decodeIcon
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
private ImageIcon decodeIcon(String url) throws IOException {
try (InputStream stream = new URL(url).openStream()) {
List<BufferedImage> images = ICODecoder.read(stream);
for (BufferedImage image : images) {
if (image.getWidth() == 16) return new ImageIcon(image);
}
return scaleImage(images.get(0));
}
}
示例3: read
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
private static BufferedImage read(URL imageSource, boolean isIcon) throws Exception {
if (isIcon) {
java.util.List<BufferedImage> images = ICODecoder.read(imageSource.openStream());
return images.get(0);
} else {
return ImageIO.read(imageSource);
}
}
示例4: main
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Image2ascii convert = new Image2ascii();
java.util.List<BufferedImage> images = ICODecoder.read(new File("/home/luog/favicon.ico"));
String s = convert.convert(images.get(0), true);
if (images.size() > 0) {
for (int i = 0; i < images.size(); ++i) {
ImageIO.write(images.get(i), "png", new File("/home/luog/f" + i + ".png"));
}
}
IO.writeContent(s, new File("/home/luog/a.txt"));
}
示例5: fetchFavIcon
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
/**
* Fetch a favicon for a given location.
*
* @param browserLoc the location of a browser for which a favicon is to be fetched.
* @return the favicon for the browser location or null if no such favicon could be determined.
*/
public ImageView fetchFavIcon(final String browserLoc) {
// fetch the favicon from cache if it is there.
final String serverRoot = findRootLoc(browserLoc);
ImageView cachedFavicon = faviconCache.get(serverRoot);
if (cachedFavicon != null) return cachedFavicon;
// ok, it wasn't in the cache, create a placeholder, to be used if the site doesn't have a favicon.
final ImageView favicon = new ImageView();
// if the serverRoot of the location cannot be determined, just return the placeholder.
if (serverRoot == null) return favicon;
// store the new favicon placeholder in the cache.
faviconCache.put(serverRoot, favicon);
// lazily fetch the real favicon.
final Task<Image> task = new Task<Image>() {
@Override
protected Image call() throws Exception {
// fetch the favicon from the server if we can.
URL url = new URL(serverRoot + "/favicon.ico");
// decode the favicon into an awt image.
List<BufferedImage> imgs = ICODecoder.read(url.openStream());
// if the decoding was successful convert to a JavaFX image and return it.
if (imgs.size() > 0) {
return ResourceUtil.bufferedImageToFXImage(imgs.get(0), 0, 16, true, true);
} else {
return null;
}
}
};
// replace the placeholder in a favicon whenever the lazy fetch completes.
task.valueProperty().addListener((observableValue, oldImage, newImage) -> {
if (newImage != null) {
favicon.setImage(newImage);
}
});
threadpool.execute(task);
return favicon;
}
示例6: getIconImage
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
private static Image getIconImage(InputStream in) throws IOException {
List<BufferedImage> images = ICODecoder.read(in);
BufferedImage image = Collections.max(images, Comparator.comparingInt(BufferedImage::getWidth));
return SwingFXUtils.toFXImage(image, null);
}
示例7: fetchFavIcon
import net.sf.image4j.codec.ico.ICODecoder; //导入方法依赖的package包/类
/**
* Fetch a favicon for a given location.
*
* @param browserLoc the location of a browser for which a favicon is to be fetched.
* @return the favicon for the browser location or null if no such favicon could be determined.
*/
public ImageView fetchFavIcon(final String browserLoc) {
// fetch the favicon from cache if it is there.
final String serverRoot = findRootLoc(browserLoc);
ImageView cachedFavicon = faviconCache.get(serverRoot);
if (cachedFavicon != null) return cachedFavicon;
// ok, it wasn't in the cache, create a placeholder, to be used if the site doesn't have a favicon.
final ImageView favicon = new ImageView();
// if the serverRoot of the location cannot be determined, just return the placeholder.
if (serverRoot == null) return favicon;
// store the new favicon placeholder in the cache.
faviconCache.put(serverRoot, favicon);
// lazily fetch the real favicon.
final Task<Image> task = new Task<Image>() {
@Override
protected Image call() throws Exception {
// fetch the favicon from the server if we can.
URL url = new URL(serverRoot + "/favicon.ico");
// decode the favicon into an awt image.
List<BufferedImage> imgs = ICODecoder.read(url.openStream());
// if the decoding was successful convert to a JavaFX image and return it.
if (imgs.size() > 0) {
return ResourceUtil.bufferedImageToFXImage(imgs.get(0), 0, 16, true, true);
} else {
return null;
}
}
};
// replace the placeholder in a favicon whenever the lazy fetch completes.
task.valueProperty().addListener((observableValue, oldImage, newImage) -> {
if (newImage != null) {
favicon.setImage(newImage);
}
});
threadpool.execute(task);
return favicon;
}