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


Java ImageReader.read方法代码示例

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


在下文中一共展示了ImageReader.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:InputImageTests.java

示例2: newData

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Override
public void newData(byte[] bytes) {
	if(Dashboard.visionInitialized()){
		Mat m = CvProcessing.byteArray2Mat(bytes);
		Dashboard.setForVision(m);
	}
	if(mode == DisplayMode.Normal){
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpeg");
 
        ImageReader reader = (ImageReader) readers.next();
        Object source = bis; 
       
		try {
			ImageInputStream iis = ImageIO.createImageInputStream(source); 
		    reader.setInput(iis, true);
		    ImageReadParam param = reader.getDefaultReadParam();
		    BufferedImage image = reader.read(0, param); 
		    setImage(image);
		} catch (IOException e) {
		}
	}

}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:25,代码来源:CameraViewer.java

示例3: 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;
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:19,代码来源:GifFramesExtractor.java

示例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");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:TruncatedImageWarningTest.java

示例5: main

import javax.imageio.ImageReader; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    Iterator<ImageReader> readers = ImageIO.getImageReadersBySuffix("simp");
    ImageReader simpReader = null;
    if (readers.hasNext()) {
        simpReader = readers.next();
        System.out.println("reader="+simpReader);
    }
    if (simpReader == null) {
        throw new RuntimeException("Reader not found.");
    }

    ImageReaderSpi spi = simpReader.getOriginatingProvider();
    IIOMetadataFormat spiFmt =
        spi.getImageMetadataFormat("simp_metadata_1.0");
    System.out.println("fmt from SPI=" + spiFmt);

    ByteArrayInputStream bais = new ByteArrayInputStream(simpData);
    ImageInputStream iis = new MemoryCacheImageInputStream(bais);
    simpReader.setInput(iis);
    BufferedImage bi = simpReader.read(0);
    System.out.println(bi);
    IIOMetadata metadata = simpReader.getImageMetadata(0);
    System.out.println("Image metadata="+metadata);
    IIOMetadataFormat format =
        metadata.getMetadataFormat("simp_metadata_1.0");
    System.out.println("Image metadata format="+format);
    if (format == null) {
        throw new RuntimeException("MetadataFormat not found.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:TestSIMPPlugin.java

示例6: testCropFullImageScaled

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testCropFullImageScaled() throws IOException {
  ImageReader reader = getReader("prime_shaped.jpg");
  TurboJpegImageReadParam param = (TurboJpegImageReadParam) reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(0, 0, reader.getWidth(2), reader.getHeight(2)));
  BufferedImage img = reader.read(2, param);
  assertThat(img).hasDimensions(reader.getWidth(2), reader.getHeight(2));
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:9,代码来源:TurboJpegImageReaderTest.java

示例7: 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

示例8: testReadUnalignedRotated

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testReadUnalignedRotated() throws IOException {
  ImageReader reader = getReader("crop_unaligned_rot90.jpg");
  TurboJpegImageReadParam param = (TurboJpegImageReadParam) reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(16, 16, 339, 319));
  param.setRotationDegree(90);
  BufferedImage img = reader.read(0, param);
  assertThat(img)
      .hasDimensions(319, 339)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:12,代码来源:TurboJpegImageReaderTest.java

示例9: testType

import javax.imageio.ImageReader; //导入方法依赖的package包/类
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ReadAsGrayTest.java

示例10: testReadRegionRotatedFullWidth

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testReadRegionRotatedFullWidth() throws IOException {
  ImageReader reader = getReader("rotated_fullwidth.jpg");
  TurboJpegImageReadParam param = (TurboJpegImageReadParam) reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(0, 0, 384, 368));
  param.setRotationDegree(90);
  BufferedImage img = reader.read(1, param);
  assertThat(img)
      .hasDimensions(368, 384)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:12,代码来源:TurboJpegImageReaderTest.java

示例11: testReadUnalignedScaled

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testReadUnalignedScaled() throws IOException {
  ImageReader reader = getReader("crop_unaligned.jpg");
  ImageReadParam param = reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(87, 111, 152, 129));
  BufferedImage img = reader.read(1, param);
  assertThat(img)
      .hasDimensions(152, 129)
      .hasNoPixelsOfColor(-1 /* white */);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:11,代码来源:TurboJpegImageReaderTest.java

示例12: testUnalignedCropOnPrimeShaped

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testUnalignedCropOnPrimeShaped() throws IOException {
  ImageReader reader = getReader("prime_shaped.jpg");
  TurboJpegImageReadParam param = (TurboJpegImageReadParam) reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(131, 57, 239, 397));
  BufferedImage img = reader.read(0, param);
  assertThat(img).hasDimensions(239, 397)
          .hasNoPixelsOfColor(-1);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:10,代码来源:TurboJpegImageReaderTest.java

示例13: testCropFullHeight

import javax.imageio.ImageReader; //导入方法依赖的package包/类
@Test
public void testCropFullHeight() throws IOException {
  ImageReader reader = getReader("prime_shaped.jpg");
  TurboJpegImageReadParam param = (TurboJpegImageReadParam) reader.getDefaultReadParam();
  param.setSourceRegion(new Rectangle(192, 0, 172, 509));
  BufferedImage img = reader.read(0, param);
  assertThat(img).hasDimensions(172, 509);
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:9,代码来源:TurboJpegImageReaderTest.java

示例14: readTestImage

import javax.imageio.ImageReader; //导入方法依赖的package包/类
public static BufferedImage readTestImage(String fileName,
                               BufferedImage dest,
                               Rectangle srcROI)
{
    BufferedImage bi = null;

    try {
        FileImageInputStream is =
            new FileImageInputStream(new File(fileName));
        ImageReader reader =
            (ImageReader)ImageIO.getImageReaders(is).next();
        ImageReadParam param = reader.getDefaultReadParam();
        if (dest != null) {
            param.setDestination(dest);
        }
        if (srcROI != null) {
            param.setSourceRegion(srcROI);
        }
        reader.setInput(is);
        bi = reader.read(0, param);
    } catch (IOException e) {
        System.err.println("Error " + e +
                           " when reading file: " + fileName);
        throw new RuntimeException(e);
    }

    return bi;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:JPEGsNotAcceleratedTest.java

示例15: doTest

import javax.imageio.ImageReader; //导入方法依赖的package包/类
protected void doTest() throws IOException {
    BufferedImage biSrc = getSrc();

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    IIOMetadata imageMetadata =
        writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);

    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);

    IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
    writer.write(streamMetadata, iioImg, writeParam);
    ios.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    ImageReader reader = ImageIO.getImageReader(writer);
    reader.setInput(iis);
    BufferedImage dst = reader.read(0);

    // do test
    int x = dx / 2;
    int y = height / 2;

    for (int i = 0; i < usedColors.length; i++) {
        int dstRgb = dst.getRGB(x, y);
        System.out.println("dstColor: " + Integer.toHexString(dstRgb));
        int srcRgb = usedColors[i].getRGB();
        System.out.println("srcColor: " + Integer.toHexString(srcRgb));
        if (dstRgb != srcRgb) {
            throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
        }
        x += dx;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:RGBImageTest.java


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