當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。