本文整理汇总了Java中javax.imageio.ImageReader.setInput方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReader.setInput方法的具体用法?Java ImageReader.setInput怎么用?Java ImageReader.setInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageReader
的用法示例。
在下文中一共展示了ImageReader.setInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFrames
import javax.imageio.ImageReader; //导入方法依赖的package包/类
static ArrayList<BufferedImage> getFrames(File gif) throws IOException {
ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
ImageReader ir = new GIFImageReader(new GIFImageReaderSpi());
ir.setInput(ImageIO.createImageInputStream(gif));
for (int i = 0; i < ir.getNumImages(true); i++) {
frames.add(ir.read(i));
}
// Release resources for Garbage Collection
ir.dispose();
return frames;
}
示例2: runTest
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context)ctx;
final ImageReader reader = ictx.reader;
final boolean seekForwardOnly = ictx.seekForwardOnly;
final boolean ignoreMetadata = ictx.ignoreMetadata;
do {
try {
ImageInputStream iis = ictx.createImageInputStream();
reader.setInput(iis, seekForwardOnly, ignoreMetadata);
reader.getImageMetadata(0);
reader.reset();
iis.close();
ictx.closeOriginalStream();
} catch (IOException e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
示例3: main
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
//nomarkers.jpg has YCbCr color space
String fileName = "nomarkers.jpg";
String sep = System.getProperty("file.separator");
String dir = System.getProperty("test.src", ".");
String filePath = dir+sep+fileName;
System.out.println("Test file: " + filePath);
File imageFile = new File(filePath);
ImageInputStream inputStream = ImageIO.
createImageInputStream(imageFile);
Iterator<ImageReader> readers = ImageIO.getImageReaders(inputStream);
if(readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(inputStream);
ImageTypeSpecifier typeSpecifier = reader.getRawImageType(0);
//check if ImageTypeSpecifier is null for YCbCr JPEG Image
if (typeSpecifier == null) {
throw new RuntimeException("ImageReader returns null raw image"
+ " type");
}
}
}
示例4: main
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String sep = System.getProperty("file.separator");
String dir = System.getProperty("test.src", ".");
String filePath = dir+sep+fileName;
System.out.println("Test file: " + filePath);
File f = new File(filePath);
ImageInputStream in = ImageIO.createImageInputStream(f);
ImageReader reader = ImageIO.getImageReaders(in).next();
TruncatedImageWarningTest twt = new TruncatedImageWarningTest();
reader.addIIOReadWarningListener(twt);
reader.setInput(in);
reader.read(0);
if (!twt.receivedWarning) {
throw new RuntimeException("No expected warning");
}
}
示例5: runTest
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context)ctx;
final ImageReader reader = ictx.reader;
final boolean seekForwardOnly = ictx.seekForwardOnly;
final boolean ignoreMetadata = ictx.ignoreMetadata;
do {
try {
ImageInputStream iis = ictx.createImageInputStream();
reader.setInput(iis, seekForwardOnly, ignoreMetadata);
reader.read(0);
reader.reset();
iis.close();
ictx.closeOriginalStream();
} catch (IOException e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
示例6: readFrom
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static ITXtTest readFrom(File f) {
try (ImageInputStream imageInputStream =
ImageIO.createImageInputStream(f)) {
ImageReader r = ImageIO.getImageReaders(imageInputStream).next();
r.setInput(imageInputStream);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
Node root = m.getAsTree(m.getNativeMetadataFormatName());
Node n = root.getFirstChild();
while (n != null && !"iTXt".equals(n.getNodeName())) {
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No iTXt node!");
}
ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
return t;
} catch (Throwable e) {
throw new RuntimeException("Reading test failed.", e);
}
}
示例7: getPngFrames
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static List<InputStream> getPngFrames(ImageInputStream imageInputStream) {
List<InputStream> result = new ArrayList<>();
try {
ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
reader.setInput(imageInputStream);
int count = reader.getNumImages(true);
for (int index = 0; index < count; index++) {
BufferedImage frame = reader.read(index);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(frame, "png", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
result.add(is);
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
示例8: testCanReuseReader
import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testCanReuseReader() throws IOException {
ImageReader reader = getReader("rgb.jp2");
BufferedImage rgbImg = reader.read(0, null);
reader.setInput(ImageIO.createImageInputStream(
new File(ClassLoader.getSystemResource("hires.jp2").getFile())));
BufferedImage bwImg = reader.read(0, null);
assertThat(rgbImg.getRGB(256, 256)).isNotEqualTo(bwImg.getRGB(256, 256));
}
示例9: doTest
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static void doTest(int type) throws IOException {
BufferedImage src = createTestImage(type);
File f = new File("test.jpg");
if (!ImageIO.write(src, "jpg", f)) {
throw new RuntimeException("Failed to write test image.");
}
ImageInputStream iis = ImageIO.createImageInputStream(f);
ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
ImageTypeSpecifier srgb = null;
ImageTypeSpecifier gray = null;
// look for gray and srgb types
while ((srgb == null || gray == null) && types.hasNext()) {
ImageTypeSpecifier t = types.next();
if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) {
gray = t;
}
if (t.getColorModel().getColorSpace() == sRGB) {
srgb = t;
}
}
if (gray == null) {
throw new RuntimeException("No gray type available.");
}
if (srgb == null) {
throw new RuntimeException("No srgb type available.");
}
System.out.println("Read as GRAY...");
testType(reader, gray, src);
System.out.println("Read as sRGB...");
testType(reader, srgb, src);
}
示例10: test
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static void test(ImageReader reader, String format)
throws IOException {
boolean gotISE = false;
File f = null;
ImageInputStream stream = null;
try {
f = File.createTempFile("imageio", ".tmp");
stream = ImageIO.createImageInputStream(f);
reader.setInput(stream, true);
try {
int numImages = reader.getNumImages(true);
} catch (IOException ioe) {
gotISE = false;
} catch (IllegalStateException ise) {
gotISE = true;
}
} finally {
if (stream != null) {
stream.close();
}
reader.dispose();
if (f != null) {
Files.delete(f.toPath());
}
}
if (!gotISE) {
throw new RuntimeException("Failed to get desired exception for " +
format + " reader!");
}
}
示例11: test
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static void test(String format) throws IOException {
System.out.println("Format: " + format);
BufferedImage src = createSrc();
ImageInputStream iis = prepareInput(src, format);
ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis);
ImageReadParam p = reader.getDefaultReadParam();
int cnt = 0;
do {
System.out.println("cnt: " + cnt);
p.setSourceRegion(new Rectangle(width / 4, height / 4,
width / 2, height / 2));
BufferedImage dst = reader.read(0, p);
final Color c = new Color(dst.getRGB(10, 10), true);
if (!sameColor(c, srcColor)) {
throw new RuntimeException(
String.format("Test failed: read color 0x%X\n",
c.getRGB()));
}
} while (++cnt < max);
}
示例12: read
import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
ImageInputStream imageInputStream = null;
ImageReader imageReader = null;
try {
imageInputStream = createImageInputStream(inputMessage.getBody());
MediaType contentType = inputMessage.getHeaders().getContentType();
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
process(irp);
imageReader.setInput(imageInputStream, true);
return imageReader.read(0, irp);
}
else {
throw new HttpMessageNotReadableException(
"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
}
finally {
if (imageReader != null) {
imageReader.dispose();
}
if (imageInputStream != null) {
try {
imageInputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
}
示例13: initializeAnnotations
import javax.imageio.ImageReader; //导入方法依赖的package包/类
private void initializeAnnotations() {
try {
ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
if (readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(iis);
IIOMetadata imageMetadata = reader.getImageMetadata(0);
org.w3c.dom.Node root = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
NodeList childNodes = root.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
org.w3c.dom.Node item = childNodes.item(i);
if (item.getNodeName().equals("tEXt")) {
org.w3c.dom.Node textNode = item;
NodeList entryNodes = textNode.getChildNodes();
for (int j = 0; j < entryNodes.getLength(); j++) {
org.w3c.dom.Node entry = entryNodes.item(j);
if (entry.getNodeName().equals("tEXtEntry")) {
NamedNodeMap attributes = entry.getAttributes();
String kw = attributes.getNamedItem("keyword").getNodeValue();
String value = attributes.getNamedItem("value").getNodeValue();
Pattern p = Pattern.compile("a1810-(\\d+)-(\\d+\\.\\d+)-(\\d+\\.\\d+)-(\\d+\\.\\d+)-(\\d+\\.\\d+)");
Matcher matcher = p.matcher(kw);
if (matcher.matches()) {
Annotation annotation = new Annotation();
annotation.setX(Double.parseDouble(matcher.group(2)));
annotation.setY(Double.parseDouble(matcher.group(3)));
annotation.setWidth(Double.parseDouble(matcher.group(4)));
annotation.setHeight(Double.parseDouble(matcher.group(5)));
annotation.setText(value);
annotation.setFill(ANNOTATION_COLOR);
annotations.add(annotation);
}
}
}
}
}
reader.dispose();
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: main
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
String format = "GIF";
ImageWriter writer =
ImageIO.getImageWritersByFormatName(format).next();
if (writer == null) {
throw new RuntimeException("No available writers for " + format);
}
BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);
ImageWriteParam p = writer.getDefaultWriteParam();
ImageTypeSpecifier type =
ImageTypeSpecifier.createFromRenderedImage(img);
IIOMetadata inImageMetadata =
writer.getDefaultImageMetadata(type, p);
IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);
// write and read image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);
ios.flush();
ios.close();
// read result
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
IIOMetadata outStreamMetadata = reader.getStreamMetadata();
GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;
if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
throw new RuntimeException("Test failed due to wrong logical screen dimension.");
}
}
示例15: Texture
import javax.imageio.ImageReader; //导入方法依赖的package包/类
public Texture(ResourceLocation location, boolean allowRP)
{
InputStream s = null;
try
{
this.location = location;
s = open(location, allowRP);
ImageInputStream stream = ImageIO.createImageInputStream(s);
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if(!readers.hasNext()) throw new IOException("No suitable reader found for image" + location);
ImageReader reader = readers.next();
reader.setInput(stream);
frames = reader.getNumImages(true);
BufferedImage[] images = new BufferedImage[frames];
for(int i = 0; i < frames; i++)
{
images[i] = reader.read(i);
}
reader.dispose();
int size = 1;
width = images[0].getWidth();
height = images[0].getHeight();
while((size / width) * (size / height) < frames) size *= 2;
this.size = size;
glEnable(GL_TEXTURE_2D);
synchronized(SplashProgress.class)
{
name = glGenTextures();
glBindTexture(GL_TEXTURE_2D, name);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)null);
checkGLError("Texture creation");
for(int i = 0; i * (size / width) < frames; i++)
{
for(int j = 0; i * (size / width) + j < frames && j < size / width; j++)
{
buf.clear();
BufferedImage image = images[i * (size / width) + j];
for(int k = 0; k < height; k++)
{
for(int l = 0; l < width; l++)
{
buf.put(image.getRGB(l, k));
}
}
buf.position(0).limit(width * height);
glTexSubImage2D(GL_TEXTURE_2D, 0, j * width, i * height, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
checkGLError("Texture uploading");
}
}
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
}
catch(IOException e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
finally
{
IOUtils.closeQuietly(s);
}
}