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


Java ImageReader类代码示例

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


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

示例1: addImageExtension

import javax.imageio.ImageReader; //导入依赖的package包/类
public File addImageExtension(File incoming) throws IOException {
	
	String format = null;
	ImageInputStream iis = ImageIO.createImageInputStream(incoming);
	Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(iis);
	while (imageReaders.hasNext()) {
	    ImageReader reader = (ImageReader) imageReaders.next();
	    format = reader.getFormatName().toLowerCase();
	    log.debug("filetype is: " + format);

	    File newfile = new File("imageimage." + format);
		if (newfile.exists()) {
			newfile.delete();    	
		}
		
	    Files.copy(incoming.toPath(), newfile.toPath());
	    incoming.delete();

	    return newfile;
	}
	return null;
	
}
 
开发者ID:ForJ-Latech,项目名称:fwm,代码行数:24,代码来源:AddableImage.java

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

示例3: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:InputImageTests.java

示例4: F2IR

import javax.imageio.ImageReader; //导入依赖的package包/类
public static ImageReader F2IR(String input) throws IOException {

		final File file = new File(input);

		// ��ȡͼƬ��ʽ
		final String formatname = GetPostfix.fromFilepath(input);

		Iterator<ImageReader> readers;
		ImageReader reader;
		ImageInputStream iis;
		readers = ImageIO.getImageReadersByFormatName(formatname);
		reader = readers.next();
		iis = ImageIO.createImageInputStream(file);
		reader.setInput(iis, false);

		return reader;
	}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:18,代码来源:File2ImageReader.java

示例5: getJPEGTablesReader

import javax.imageio.ImageReader; //导入依赖的package包/类
/**
 * Retrieves a JPEG reader which supports native JPEG stream metadata.
 */
private static ImageReader getJPEGTablesReader() {
    ImageReader jpegReader = null;

    try {
        IIORegistry registry = IIORegistry.getDefaultInstance();
        Iterator<?> readerSPIs =
            registry.getServiceProviders(ImageReaderSpi.class,
                                         new JPEGSPIFilter(),
                                         true);
        if(readerSPIs.hasNext()) {
            ImageReaderSpi jpegReaderSPI =
                (ImageReaderSpi)readerSPIs.next();
            jpegReader = jpegReaderSPI.createReaderInstance();
        }
    } catch(Exception e) {
        // Ignore it ...
    }

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

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

示例7: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ReadAsGrayTest.java

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

示例9: TIFF

import javax.imageio.ImageReader; //导入依赖的package包/类
/**
    * 
    * @param imageFile
    * @param band form files with multiple band
    */
public TIFF(File imageFile,int band) {
   	this.imageFile=imageFile;
       try {
           Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("tiff");
           boolean worked=false;
           while(readers.hasNext()&&!worked){
           	Object obj=readers.next();
           	if( obj instanceof TIFFImageReader){
           		reader = (TIFFImageReader)obj;
           		iis=ImageIO.createImageInputStream(imageFile);
           		reader.setInput(iis);
           		try{
           			xSize=reader.getWidth(band);
           			ySize=reader.getHeight(band);
           			bounds=new Rectangle(0,0,xSize,ySize);
           		}catch(Exception e){
           			bounds=null;
           			logger.warn("Problem reading size information");
           		}	
           		worked=true;
           	}else{
           		
           	}
           }
           if(!worked){
           	logger.warn("No reader avalaible for this image");
           }
       } catch (Exception ex) {
       	logger.error(ex.getMessage(),ex);
       }	
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:37,代码来源:TIFF.java

示例10: DestTypeTest

import javax.imageio.ImageReader; //导入依赖的package包/类
public DestTypeTest() {
    w = (ImageWriter)
        ImageIO.getImageWritersByFormatName("jpeg").next();
    w.addIIOWriteWarningListener(this);

    r = (ImageReader)
        ImageIO.getImageReadersByFormatName("jpeg").next();
    r.addIIOReadWarningListener(this);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DestTypeTest.java

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

示例12: IS2IR

import javax.imageio.ImageReader; //导入依赖的package包/类
public static ImageReader IS2IR(ImageInputStream input, String formatname) throws IOException {

		Iterator<ImageReader> readers;
		ImageReader reader;
		readers = ImageIO.getImageReadersByFormatName(formatname);
		reader = readers.next();
		reader.setInput(input, false);

		return reader;
	}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:11,代码来源:ImageStream2ImageReader.java

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

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

示例15: init

import javax.imageio.ImageReader; //导入依赖的package包/类
private static void init() {

        Iterator i = ImageIO.getImageWritersByFormatName(format);
        if (!i.hasNext()) {
            throw new RuntimeException("No available ImageWrites for "+format+" format!");
        }
        iw = (ImageWriter)i.next();

        i = ImageIO.getImageReadersByFormatName(format);
        if (!i.hasNext()) {
            throw new RuntimeException("No available ImageReaders for " +format+" format!");
        }

        ir = (ImageReader)i.next();
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:BMPPluginTest.java


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