javax.imageio

Unable to acquire image through ImageIO.read(url) because of connection timed out

做~自己de王妃 提交于 2019-12-12 08:54:03
问题 The following code always seems to fail: URL url = new URL("http://userserve-ak.last.fm/serve/126/8636005.jpg"); Image img = ImageIO.read(url); System.out.println(img); I've checked the url, and it is a valid jpg image. The error I get is: Exception in thread "main" javax.imageio.IIOException: Can't get input stream from URL! at javax.imageio.ImageIO.read(ImageIO.java:1385) at maestro.Main2.main(Main2.java:25) Caused by: java.net.ConnectException: Connection timed out at java.net

Image Metadata for a specified directory in Java

老子叫甜甜 提交于 2019-12-12 06:55:45
问题 Here I have code for displaying metadata for 1 file. I wanted to know how can I use to display metadata for a specified directory? import java.io.*; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import javax.imageio.*; import javax.imageio.stream.*; import javax.imageio.metadata.*; import java.util.Scanner; public class Metadata{ public static void main(String[] args) { Metadata meta = new Metadata(

Java: Loading png images without indexing (as BufferedImage.TYPE_4BYTE_ABGR), using javax.imageio.ImageIO.read()

风流意气都作罢 提交于 2019-12-12 05:59:05
问题 I am trying to load a PNG image using the javax.imageio.ImageIO.read() method. However, I want the resulting type to be "BufferedImage.TYPE_4BYTE_ABGR", but it ends up as an indexed image ("BufferedImage.TYPE_BYTE_INDEXED"). Is there any way to load an image as unindexed, when the original image is indexed? There are about 120 images, so it would take too long to make them all unindexed by hand. 回答1: If you're not opposed to using JAI, you can create a rendering chain for the RenderedImage

Read keywords in xmp from png with Java

不羁的心 提交于 2019-12-12 05:27:56
问题 I am trying to get keywords added to a PNG image file in Photoshop using Java. I tried this method using the imageio in Java: http://johnbokma.com/java/obtaining-image-metadata.html However, all I get is the following: Format name: javax_imageio_png_1.0 <javax_imageio_png_1.0> <IHDR width="128" height="128" bitDepth="8" colorType="RGBAlpha" compressionMethod="deflate" filterMethod="adaptive" interlaceMethod="none"/> <cHRM whitePointX="31269" whitePointY="32899" redX="63999" redY="33001"

Why does Java ImageIO generate different images on different machines (linux vs Windows)?

纵饮孤独 提交于 2019-12-12 02:55:00
问题 I'm using javax.imageio to generate images from text strings on Windows and Linux, and I find the images are very different in quality (Linux = poor quality, small physical size, although same dimentions). Linux (Ubunutu), 443 bytes Windows 7, 1,242 bytes I'm using the same font file (From Windows, uploaded to linux), and using this code to generate the images. Any idea how to improve the quality of the linux-generated images? Why are the generated images different in the first place? I've

How To Save My Screenshot in java

戏子无情 提交于 2019-12-12 01:16:41
问题 I'm making a program that takes a screenshot and I want to have it so that i have a JButton with an actionlistener that when pressed it saves the image to a certain folder that if does not already exists it makes. here is what I thought I should do: @Override public void actionPerformed(ActionEvent arg0) { File dir = new File("C://SnippingTool+/" + date.getDay()); dir.mkdirs(); try { ImageIO.write(shot, "JPG", dir); } catch (IOException e) { e.printStackTrace(); } } }); I think it has

imageio.jar works as standalone but not as a web project

别等时光非礼了梦想. 提交于 2019-12-11 23:34:23
问题 I am having a spring mvc project with the basic pom. I also have imageio.jar in build path. String format="tif"; System.out.println(format); Iterator<ImageReader> readers = ImageIO .getImageReadersByFormatName(format); System.out.println(readers.hasNext()); Iterator<ImageWriter> writers = ImageIO .getImageWritersByFormatName("tiff"); System.out.println(writers.hasNext()); When the above code is executes as a stand alone program i get the output as follows tif true true but when i add it to a

ImageIO wont import BufferedImage correctly

允我心安 提交于 2019-12-11 18:08:51
问题 Error thrown-- Exception in thread "Thread-3" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) Code-- try { playerImage = ImageIO.read(Player.class .getResourceAsStream("/toon.png")); } catch (IOException e) { e.printStackTrace(); } File path-- H:\workspace\Isaac\resources\toon.png Ive researched this a bit but none of the solutions have really worked for me. any ideas? 回答1: If Isaac is your project folder, then the way your are reading should

Add/remove ImageReader from jar to ImageIO-registry

感情迁移 提交于 2019-12-11 13:39:32
问题 In jar jai_imageio.jar there is class: com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader So i add jai_imageio.jar (and jai_core.jar, jai_codec.jar) to classpath. But this class seems not to be accessable for ImageIO. So this code: ImageIO.scanForPlugins(); IIORegistry.getDefaultInstance().registerApplicationClasspathSpis(); Iterator<ImageReader> ir = ImageIO.getImageReadersByFormatName("jpeg"); while(ir.hasNext()) { ImageReader r = ir.next(); System.out.println("can read raster: " +

Reading Grayscale PNG image files without distortion

穿精又带淫゛_ 提交于 2019-12-11 12:56:53
问题 I need to read and process a large number of PNG files that are grayscale. By that I mean that if they are opened in either Photoshop or GIMP, the image mode is Grayscale - not an RGB image with grayscale values. ImageIO does not seem to achieve this. It appears to treat all image files as sRGB. This mangles grayscale values. I need to read and process these PNG files where (in my code) each pixel has exactly the same value as if I had opened the grayscale file in Photoshop or GIMP. Does