Java Code Examples for javax.imageio.ImageIO.getImageReadersByFormatName()

The following are Jave code examples for showing how to use getImageReadersByFormatName() of the javax.imageio.ImageIO class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sumo   File: OverviewTest.java   View Source Code Vote up 6 votes
/**
 * Test method for {@link org.geoimage.viewer.widget.GeoOverviewToolbar#GeoOverviewToolbar()}.
 */
@Test
public void testCreateOverviewFile() {
	try{
		ImageIO.scanForPlugins();
		Object o=ImageIO.getImageReadersByFormatName("tiff");
		List<GeoImageReader> readers= GeoImageReaderFactory.createReaderForName(safe,PlatformConfiguration.getConfigurationInstance().getS1GeolocationAlgorithm());
		Sentinel1SLC slc=(Sentinel1SLC)(readers.get(0));
		
		Overview overview=new Overview(null);
		overview.setGir(slc);
		overview.buildOverview();
		
		assertTrue(true);
	}catch(Exception e){
		e.printStackTrace();
		assertTrue(false);
	}	
	
}
 
Example 2
Project: sucok-framework   File: ImageSizeUtils.java   View Source Code Vote up 6 votes
public static BufferedImage cut(String format, InputStream src, int x, int y, int w, int h) throws IOException {
	Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName(format);
	ImageReader reader = (ImageReader) iterator.next();
	ImageInputStream iis = ImageIO.createImageInputStream(src);
	reader.setInput(iis, true);
	ImageReadParam param = reader.getDefaultReadParam();
	int imgWidth = reader.getWidth(0);
	int imgHeight = reader.getHeight(0);
	if (x + w > imgWidth) {
		w = imgWidth - x;
	}
	if (y + h > imgHeight) {
		h = imgHeight - y;
	}
	Rectangle rect = new Rectangle(x, y, w, h);
	param.setSourceRegion(rect);
	BufferedImage bi = reader.read(0, param);
	return bi;
}
 
Example 3
Project: SpotSpotter   File: File2ImageReader.java   View Source Code Vote up 6 votes
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;
	}
 
Example 4
Project: FlashLib   File: CameraViewer.java   View Source Code Vote up 6 votes
@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) {
		}
	}

}
 
Example 5
Project: sumo   File: TIFF.java   View Source Code Vote up 5 votes
/**
    * 
    * @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);
       }	
}
 
Example 6
Project: sucok-framework   File: ImageUtils.java   View Source Code Vote up 5 votes
public static BufferedImage read(String format, InputStream in) throws IOException {
	Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName(format);
	ImageReader reader = (ImageReader) iterator.next();
	ImageInputStream iis = ImageIO.createImageInputStream(in);
	reader.setInput(iis, true);
	ImageReadParam param = reader.getDefaultReadParam();
	BufferedImage bi = reader.read(0, param);
	return bi;
}
 
Example 7
Project: SpotSpotter   File: ImageStream2ImageReader.java   View Source Code Vote up 5 votes
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;
	}
 
Example 8
Project: openjdk-jdk10   File: TIFFJPEGDecompressor.java   View Source Code Vote up 5 votes
public void beginDecoding() {
    // Initialize the JPEG reader if needed.
    if(this.JPEGReader == null) {
        // Get all JPEG readers.
        Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("jpeg");

        if(!iter.hasNext()) {
            throw new IllegalStateException("No JPEG readers found!");
        }

        // Initialize reader to the first one.
        this.JPEGReader = iter.next();

        this.JPEGParam = JPEGReader.getDefaultReadParam();
    }

    // Get the JPEGTables field.
    TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
    TIFFField f =
        tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_TABLES);

    if (f != null) {
        this.hasJPEGTables = true;
        this.tables = f.getAsBytes();
    } else {
        this.hasJPEGTables = false;
    }
}
 
Example 9
Project: openjdk-jdk10   File: GetReaderWriterInfo.java   View Source Code Vote up 5 votes
private static void testGetReaderFormatNames() {
    String[] names = ImageIO.getReaderFormatNames();
    for (String n : names) {
        Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(n);
        if (!it.hasNext()) {
            throw new RuntimeException("getReaderFormatNames returned " +
                                       "an unknown name: " + n);
        }
    }
}
 
Example 10
Project: openjdk-jdk10   File: WBMPPluginTest.java   View Source Code Vote up 5 votes
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();
    }
 
Example 11
Project: openjdk-jdk10   File: BMPPluginTest.java   View Source Code Vote up 5 votes
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();
    }
 
Example 12
Project: imageio-jnr   File: TurboJpegImageReaderTest.java   View Source Code Vote up 5 votes
@Test
public void testReaderIsRegistered() {
  Supplier<Iterator<ImageReader>> getReaderIter = () -> ImageIO.getImageReadersBySuffix("jpg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
  getReaderIter = () -> ImageIO.getImageReadersByMIMEType("image/jpeg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
  getReaderIter = () -> ImageIO.getImageReadersByFormatName("jpeg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
}
 
Example 13
Project: sumo   File: ImageLayer.java   View Source Code Vote up 4 votes
/**
   *
   * @param gir
   */
  public ImageLayer(GeoImageReader gir) {
  	iReader=ImageIO.getImageReadersByFormatName("png");
pngReader=(ImageReader)iReader.next();

      this.activeGir = gir;
      poolSize = Integer.parseInt(ResourceBundle.getBundle("GeoImageViewer").getString("maxthreads"));
      //poolSize=Runtime.getRuntime().availableProcessors();
      //poolExcutorService = Executors.newFixedThreadPool(poolSize);
      poolExcutorService = new ThreadPoolExecutor(1,poolSize,100, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());//,new ThreadPoolExecutor.DiscardOldestPolicy());


      submitedTiles = new ArrayList<String>();

      setName(gir);

      activeBand = 0;
      levels = (int) (Math.sqrt(Math.max(gir.getWidth() / Constant.TILE_SIZE_DOUBLE, gir.getHeight() / Constant.TILE_SIZE_DOUBLE))) + 1;
      maxlevels = (int) (Math.sqrt(Math.max(gir.getWidth() / (Constant.TILE_SIZE_DOUBLE*2), gir.getHeight() / (Constant.TILE_SIZE_DOUBLE*2)))) +1;  //massimo livello di zoom
      curlevel = levels;

      //TODO Understand the meaning of this values for padding
      xpadding = (((1 << levels) << 8) - gir.getWidth()) / 2;  // is equal to(int)((Math.pow(2,levels+8)- gir.getWidth())/2);
      ypadding = (((1 << levels) << 8) - gir.getHeight()) / 2; //			   (int)((Math.pow(2,levels+8)- gir.getHeight())/2);

      String temp = SumoPlatform.getApplication().getConfiguration().getMaxTileBuffer();
      int maxBuffer = Integer.parseInt(temp);
      tcm = new TextureCacheManager(maxBuffer);
      setInitialContrast();
      maxnumberoftiles = SumoPlatform.getApplication().getConfiguration().getMaxNumOfTiles();
      createMatrixTileOrder();

      int tileSize = (int)(Constant.TILESIZE / gir.getPixelsize()[0]);
      if(tileSize < Constant.TILESIZEPIXELS) tileSize = Constant.TILESIZEPIXELS;

      this.horizontalTilesImage = gir.getWidth() / tileSize;
      this.verticalTilesImage= gir.getHeight()/ tileSize;

   // the real size of tiles
      this.realTileSizeX = gir.getWidth() / horizontalTilesImage;
      this.realTileSizeY = gir.getHeight() / verticalTilesImage;


  }
 
Example 14
Project: springboot-training   File: ImageUtil.java   View Source Code Vote up 4 votes
private ImageReader getImageReader(final String imgType) {
	// 建立图片读取器
	Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imgType);
	return readers.next();
}