当前位置: 首页>>代码示例>>Java>>正文


Java ImageReader.dispose方法代码示例

本文整理汇总了Java中javax.imageio.ImageReader.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReader.dispose方法的具体用法?Java ImageReader.dispose怎么用?Java ImageReader.dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.ImageReader的用法示例。


在下文中一共展示了ImageReader.dispose方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:phweda,项目名称:MFM,代码行数:12,代码来源:VideoUtils.java

示例2: getPictureSize

import javax.imageio.ImageReader; //导入方法依赖的package包/类
/**
 * Extracts the picture size of a given Image.
 *
 * @param path Path to the image
 * @return Image-size in pixel
 * @throws IOException Throws exception when file-access fails
 */
public static Dimension getPictureSize(final String path) throws IOException {
    try (ImageInputStream in = ImageIO.createImageInputStream(path)) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
        if (readers.hasNext()) {
            ImageReader reader = readers.next();
            try {
                reader.setInput(in);
                return new Dimension(reader.getWidth(0), reader.getHeight(0));
            } finally {
                reader.dispose();
            }
        }
        return null;
    }
}
 
开发者ID:ProjectIndoor,项目名称:projectindoorweb,代码行数:23,代码来源:TransformationHelper.java

示例3: run

import javax.imageio.ImageReader; //导入方法依赖的package包/类
/**
 * Gets the size of an image.
 *
 * @param name the image name
 * @param in the input stream
 * @return the size of the image
 *
 * @throws BrokenImageException if the image is faulty
 * @throws UnrecognizedImageTypeException if the image type is unknown
 * @throws IOException if reading the image goes wrong
 */
public Dimension run(String name, InputStream in) throws IOException {
  final ImageInputStream stream = new MemoryCacheImageInputStream(in);

  final Iterator<ImageReader> i = ImageIO.getImageReaders(stream);
  if (!i.hasNext()) throw new UnrecognizedImageTypeException(name);

  final ImageReader reader = i.next();
  try {
    reader.setInput(stream);
    return new Dimension(reader.getWidth(0), reader.getHeight(0));
  }
  finally {
    reader.dispose();
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:27,代码来源:ImageIOImageLoader.java

示例4: getImageDimensions

import javax.imageio.ImageReader; //导入方法依赖的package包/类
/**
 * getImageDimensions.
 *
 * @param resourceFile File
 * @return Dimension
 */
static Dimension getImageDimensions(final File resourceFile) {
    registerAllServicesProviders();

    try (ImageInputStream in = createImageInputStream(resourceFile)) {
        final Iterator<ImageReader> readers = getImageReaders(in);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(in);
                return new Dimension(reader.getWidth(0), reader.getHeight(0));
            } finally {
                reader.dispose();
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:ubleipzig,项目名称:iiif-producer,代码行数:26,代码来源:JAI.java

示例5: testUpdateIcon

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testUpdateIcon() throws IOException {
    final LinkedMultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
    multipartData.add("icon", new InputStreamResource(getClass().getResourceAsStream("test-image.png")));

    final ResponseEntity<Connector> updated = post("/api/v1/connectors/twitter/icon",
        multipartData, Connector.class, tokenRule.validToken(), HttpStatus.OK,
        multipartHeaders());

    assertThat(updated.getBody().getId()).isPresent();
    assertThat(updated.getBody().getIcon()).isNotBlank().startsWith("db:");

    final ResponseEntity<ByteArrayResource> got = get("/api/v1/connectors/twitter/icon", ByteArrayResource.class);
    assertThat(got.getHeaders().getFirst("Content-Type")).isEqualTo("image/png");

    try (ImageInputStream iis = ImageIO.createImageInputStream(got.getBody().getInputStream());) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(iis);
                final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
            } finally {
                reader.dispose();
            }
        }
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:31,代码来源:ConnectorsITCase.java

示例6: 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
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:BufferedImageHttpMessageConverter.java

示例7: 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!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:AllowSearch.java

示例8: 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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:44,代码来源:ImagePanel.java

示例9: connectorIconShouldHaveCorrectContentType

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void connectorIconShouldHaveCorrectContentType() throws IOException {
    try (MockWebServer mockWebServer = new MockWebServer(); final Buffer resultBuffer = new Buffer()) {
        mockWebServer.start();

        resultBuffer.writeAll(Okio.source(getClass().getResourceAsStream("test-image.png")));

        mockWebServer.enqueue(new MockResponse().setHeader(CONTENT_TYPE, "image/png").setBody(resultBuffer));

        final Connector connector = new Connector.Builder().id("connector-id").icon(mockWebServer.url("/u/23079786").toString())
            .build();
        when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(connector);
        when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(Collections.emptyList()));

        final Response response = handler.getConnectorIcon("connector-id").get();

        assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK).as("Wrong status code");
        assertThat(response.getHeaderString(CONTENT_TYPE)).isEqualTo("image/png").as("Wrong content type");
        assertThat(response.getHeaderString(CONTENT_LENGTH)).isEqualTo("2018").as("Wrong content length");

        final StreamingOutput so = (StreamingOutput) response.getEntity();
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try (BufferedSink sink = Okio.buffer(Okio.sink(bos)); BufferedSource source = new Buffer();
            ImageInputStream iis = ImageIO.createImageInputStream(source.inputStream());) {
            so.write(sink.outputStream());
            source.readAll(sink);
            final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
            if (readers.hasNext()) {
                final ImageReader reader = readers.next();
                try {
                    reader.setInput(iis);
                    final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                    assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                    assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
                } finally {
                    reader.dispose();
                }
            }
        }
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:42,代码来源:ConnectorHandlerTest.java

示例10: testUpdateConnectorAndIconViaMultipart

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testUpdateConnectorAndIconViaMultipart() throws IOException {
    final Connector initialConnector = dataManager.fetch(Connector.class, "twitter");

    assertThat(initialConnector.getIcon()).isNotBlank().doesNotStartWith("db:");

    final Connector connectorWithNewdescription = new Connector.Builder().createFrom(initialConnector)
        .description("Updated!").build();

    final LinkedMultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
    multipartData.add("connector", connectorWithNewdescription);
    multipartData.add("icon", new InputStreamResource(getClass().getResourceAsStream("test-image.png")));

    final ResponseEntity<Void> updated = put("/api/v1/connectors/twitter",
        multipartData, Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT,
        multipartHeaders());

    final ResponseEntity<Connector> updatedConnector = get("/api/v1/connectors/twitter", Connector.class);

    assertThat(updatedConnector.getBody().getId()).isPresent();
    assertThat(updatedConnector.getBody().getIcon()).isNotBlank().startsWith("db:");
    assertThat(updatedConnector.getBody().getDescription()).isNotBlank().isEqualTo("Updated!");

    final ResponseEntity<ByteArrayResource> got = get("/api/v1/connectors/twitter/icon", ByteArrayResource.class);
    assertThat(got.getHeaders().getFirst("Content-Type")).isEqualTo("image/png");

    try (ImageInputStream iis = ImageIO.createImageInputStream(got.getBody().getInputStream());) {
        final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
        if (readers.hasNext()) {
            final ImageReader reader = readers.next();
            try {
                reader.setInput(iis);
                final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
                assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
                assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
            } finally {
                reader.dispose();
            }
        }
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:42,代码来源:ConnectorsITCase.java

示例11: readImage

import javax.imageio.ImageReader; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param source Description of the Parameter
 * @return Description of the Return Value
 * @throws IOException Description of the Exception
 */
public static BufferedImage readImage(Object source) throws IOException {
    ImageInputStream stream = ImageIO.createImageInputStream(source);
    if (stream == null) {
        if (source instanceof java.net.URL) {
            return ImageIO.read((java.net.URL) source);
        } else {
            return null;
        }
    }
    Iterator<?> it = ImageIO.getImageReaders(stream);
    if (!it.hasNext()) {
        // bug with firefox 2
        BufferedImage buf = null;
        if (source instanceof File) {
            buf = ImageIO.read((File) source);
        }
        return buf;
    }
    ImageReader reader = (ImageReader) it.next();
    reader.setInput(stream);
    ImageReadParam param = reader.getDefaultReadParam();

    ImageTypeSpecifier typeToUse = null;
    boolean looking = true;
    for (Iterator<?> i = reader.getImageTypes(0); i.hasNext() && looking; ) {
        ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
        if (type.getColorModel().getColorSpace().getNumComponents() == 1) {
            typeToUse = type;
            looking = false;
        } else if (type.getColorModel().getColorSpace().isCS_sRGB()) {
            typeToUse = type;
            looking = false;
        }
    }
    if (typeToUse != null) {
        param.setDestinationType(typeToUse);
    }

    BufferedImage b = null;
    try {
        b = reader.read(0, param);
    } catch (Exception e) {
        e.printStackTrace();
    }

    reader.dispose();
    stream.close();
    return b;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:57,代码来源:YassUtils.java

示例12: 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);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:66,代码来源:SplashProgress.java


注:本文中的javax.imageio.ImageReader.dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。