當前位置: 首頁>>代碼示例>>Java>>正文


Java FileImageInputStream類代碼示例

本文整理匯總了Java中javax.imageio.stream.FileImageInputStream的典型用法代碼示例。如果您正苦於以下問題:Java FileImageInputStream類的具體用法?Java FileImageInputStream怎麽用?Java FileImageInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileImageInputStream類屬於javax.imageio.stream包,在下文中一共展示了FileImageInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: computeHeaderSize

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
/**
 * Searches for the location of the code continuous stream in the encoded image
 *
 * @return returns the size of the header from the original encoded image
 */
private int computeHeaderSize(){
    int headerSize = 0;
    try (FileImageInputStream file = new FileImageInputStream(this.fileOutput)) {
        this.boxReader = new BoxReader(file, file.length(), new BoxListener());
        this.boxReader.getFileLength();
        Box box;
        do {
            box = this.boxReader.readBox();
            if (box.getSymbol().equals(CONTIGUOUS_CODESTREAM)) {
                headerSize = (int) box.getPosition();
            }
        }
        while (!box.getSymbol().equals(CONTIGUOUS_CODESTREAM));
    } catch (IOException e) {
        logger.warning(e.getMessage());
    }
    return headerSize;
}
 
開發者ID:senbox-org,項目名稱:s2tbx,代碼行數:24,代碼來源:JP2ImageWriter.java

示例2: main

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:ImageStreamFromRAF.java

示例3: getImageDim

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
private Dimension getImageDim(final String path, final String suffix) throws ProcessingException {
  Dimension result = null;
  Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
  if (iter.hasNext()) {
    ImageReader reader = iter.next();
    try {
      ImageInputStream stream = new FileImageInputStream(new File(path));
      reader.setInput(stream);
      int width = reader.getWidth(reader.getMinIndex());
      int height = reader.getHeight(reader.getMinIndex());
      result = new Dimension(width, height);
    }
    catch (IOException e) {
      throw new ProcessingException(e.getMessage());
    }
    finally {
      reader.dispose();
    }
  }
  else {
    throw new ProcessingException("No reader found for given format: " + suffix);
  }
  return result;
}
 
開發者ID:innovad,項目名稱:4mila-1.0,代碼行數:25,代碼來源:MapProcessService.java

示例4: getImageDimension

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
/**
 * Gets image dimensions for given file
 *
 * @param imgFile image file
 * @return dimensions of image
 * @throws IOException if the file is not a known image
 */
public static Dimension getImageDimension(File imgFile) throws IOException {
    int pos = imgFile.getName().lastIndexOf(".");
    if (pos == -1)
        throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
    String suffix = imgFile.getName().substring(pos + 1);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(imgFile);
            reader.setInput(stream);
            int width = reader.getWidth(reader.getMinIndex());
            int height = reader.getHeight(reader.getMinIndex());
            return new Dimension(width, height);
        } finally {
            reader.dispose();
        }
    }

    throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
開發者ID:patrickfav,項目名稱:density-converter,代碼行數:29,代碼來源:ImageUtil.java

示例5: loadImage

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
private BufferedImage loadImage(File file) {
  Iterator<ImageReader> it = ImageIO.
                        getImageReadersByMIMEType("image/png");
  if (it.hasNext()) {
    try {
      ImageReader reader = it.next();
      reader.setInput(new FileImageInputStream(file));
      BufferedImage image = reader.read(0);
      return image;
    } catch (IOException ex) {
      Logger.getLogger(BlockView.class.getName()).log(Level.SEVERE, null,
                                                      ex);
    }
  }
  return null;
}
 
開發者ID:alex-ac,項目名稱:LevelEditor,代碼行數:17,代碼來源:BlockView.java

示例6: doesImageFitBox

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public static boolean doesImageFitBox(FileHandle fileHandle, float width, float height) {
    boolean result = false;
    String suffix = fileHandle.extension();
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(fileHandle.file());
            reader.setInput(stream);
            int imageWidth = reader.getWidth(reader.getMinIndex());
            int imageHeight = reader.getHeight(reader.getMinIndex());
            result = imageWidth < width && imageHeight < height;
        } catch (IOException e) {
            Gdx.app.error(Utils.class.getName(), "error checking image dimensions", e);
        } finally {
            reader.dispose();
        }
    } else {
        Gdx.app.error(Utils.class.getName(), "No reader available to check image dimensions");
    }
    return result;
}
 
開發者ID:raeleus,項目名稱:skin-composer,代碼行數:23,代碼來源:Utils.java

示例7: doInBackground

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
@Override
protected Void doInBackground() throws Exception {
	if (files.isEmpty()) {
		return null;
	}
	Iterator<ImageReader> iterator = ImageIO.getImageReadersBySuffix("dds");
	if (iterator.hasNext()){
		ImageReader imageReader = iterator.next();
		imageReader.setInput(new FileImageInputStream(file));
		mipMapMax = imageReader.getNumImages(true);
		if (imageIndex > mipMapMax || imageIndex < 0) {
			throw new IOException("imageIndex ("+imageIndex+") not found");
		}
		BufferedImage image = imageReader.read(imageIndex);
		format = imageReader.getFormatName();
		if (type == ColorType.YCOCG) DDSUtil.decodeYCoCg(image);
		if (type == ColorType.YCOCG_SCALED) DDSUtil.decodeYCoCgScaled(image);
		if (type == ColorType.ALPHA_EXPONENT) DDSUtil.decodeAlphaExponent(image);
		if (!alpha || !red || !green || !blue) DDSUtil.showColors(image, alpha, red, green, blue);
		item = new Item(image, mipMapMax, file);
	}
	return null;
}
 
開發者ID:Emd4600,項目名稱:SporeModder,代碼行數:24,代碼來源:Viewer.java

示例8: isImage

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public boolean isImage(String path) {
    final String ext = FilenameUtils.getExtension(path);
    if (ext.length() < 2) return false;
    
    final Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix(ext);

    if (it.hasNext()) {
        final ImageReader r = it.next();
        try {
            ImageInputStream stream = new FileImageInputStream(new File(path));
            r.setInput(stream);
            int width = r.getWidth(r.getMinIndex());
            int height = r.getHeight(r.getMinIndex());
            r.dispose();
            stream.close();
            if ((width > 0) && (height > 0)) return true;
        } catch (IOException e) {
            return false;
        } finally { r.dispose(); }
    }
    return false;
}
 
開發者ID:konachan700,項目名稱:JNekoImageDB,代碼行數:23,代碼來源:XImgImages.java

示例9: getImageResolution

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public static Resolution getImageResolution(final String path) throws IOException {
    Resolution result = null;
    String suffix = getFileSuffix(path);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    if (iter.hasNext()) {
        ImageReader reader = iter.next();
        ImageInputStream stream = new FileImageInputStream(new File(path));
        reader.setInput(stream);
        int width = reader.getWidth(reader.getMinIndex());
        int height = reader.getHeight(reader.getMinIndex());
        result = new Resolution(width, height);
        reader.dispose();
    } else {
        logger.error("No reader found for given format: " + suffix);
    }
    return result;
}
 
開發者ID:Vidada-Project,項目名稱:vidada-server,代碼行數:18,代碼來源:ImageUtil.java

示例10: getImageDimension

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
private static Dimension getImageDimension(File imgFile) throws IOException {
    int pos = imgFile.getName().lastIndexOf(".");
    if (pos == -1)
        throw new IOException("No extension for file: " + imgFile.getAbsolutePath());
    String suffix = imgFile.getName().substring(pos + 1);
    Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
    while (iter.hasNext()) {
        ImageReader reader = iter.next();
        try {
            ImageInputStream stream = new FileImageInputStream(imgFile);
            reader.setInput(stream);
            int width = reader.getWidth(reader.getMinIndex());
            int height = reader.getHeight(reader.getMinIndex());
            return new Dimension(width, height);
        } catch (IOException e) {
            LOG.log(Level.WARNING, "Error reading: " + imgFile.getAbsolutePath(), e);
        } finally {
            reader.dispose();
        }
    }

    throw new IOException("Not a known image file: " + imgFile.getAbsolutePath());
}
 
開發者ID:castlabs,項目名稱:dashencrypt,代碼行數:24,代碼來源:ManifestCreation.java

示例11: JAXBProviderTests

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public JAXBProviderTests() {
    super();
    //Create a DataSource from a String
    String string = "Sending a JAXB generated string object to Source Provider endpoint";
    stringDS = new ByteArrayDataSource(string.getBytes(),"text/plain");

    try {
        //Create a DataSource from an image 
        File file = new File(imageResourceDir + File.separator + "test.jpg");
        ImageInputStream fiis = new FileImageInputStream(file);
        Image image = ImageIO.read(fiis);
        imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:JAXBProviderTests.java

示例12: setUp

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
public void setUp() throws Exception {
    String imageResourceDir = System.getProperty("basedir",".")+"/"+"test-resources"+File.separator+"image";

    File file = new File(imageResourceDir+File.separator+"test.jpg");
    ImageInputStream fiis = new FileImageInputStream(file);
    Image image = ImageIO.read(fiis);
    imageDS = new DataSourceImpl("image/jpeg","test.jpg",image);

    String textResourceDir = System.getProperty("basedir",".")+"/"+"test/org/apache/axis2/jaxws/xmlhttp";
    File file2 = new File(textResourceDir+File.separator+"README.txt");
    txtDS = new FileDataSource(file2);

    String resourceDir = System.getProperty("basedir",".")+"/"+"test-resources";
    File file3 = new File(resourceDir+File.separator+"log4j.properties");
    attachmentDS = new FileDataSource(file3);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:DispatchXMessageDataSourceTests.java

示例13: checkBadWriter

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
@Test
public void checkBadWriter() throws NitfFormatException {
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream("/WithBE.ntf")));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);
    NitfParser.parse(reader, parseStrategy);

    // Introduce deliberate issue
    // Introduce deliberate issue
    ImageSegment imageSegment = parseStrategy.getDataSource().getImageSegments().get(0);
    TargetId originalTargetId = imageSegment.getImageTargetId();
    TargetIdImpl newTargetId = new TargetIdImpl();
    newTargetId.setBasicEncyclopediaNumber(originalTargetId.getBasicEncyclopediaNumber());
    newTargetId.setOSuffix(originalTargetId.getOSuffix());
    newTargetId.setCountryCode(null);
    imageSegment.setImageTargetId(newTargetId);

    NitfWriter writer = new NitfFileWriter(parseStrategy.getDataSource(), "checkBadWriter.ntf");
    assertEquals(0, LOGGER.getLoggingEvents().size());
    writer.write();
    assertThat(LOGGER.getLoggingEvents(), is(Arrays.asList(LoggingEvent.error("Could not write", "Cannot generate string target identifier with null country code"))));
}
 
開發者ID:codice,項目名稱:imaging-nitf,代碼行數:26,代碼來源:BasicWriterTest.java

示例14: checkBadStreamWriter

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
@Test
public void checkBadStreamWriter() throws NitfFormatException, FileNotFoundException {
    OutputStream outputStream = new FileOutputStream("checkBadStreamWriter.ntf");
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream("/WithBE.ntf")));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);
    NitfParser.parse(reader, parseStrategy);

    // Introduce deliberate issue
    ImageSegment imageSegment = parseStrategy.getDataSource().getImageSegments().get(0);
    TargetId originalTargetId = imageSegment.getImageTargetId();
    TargetIdImpl newTargetId = new TargetIdImpl();
    newTargetId.setBasicEncyclopediaNumber(originalTargetId.getBasicEncyclopediaNumber());
    newTargetId.setOSuffix(originalTargetId.getOSuffix());
    newTargetId.setCountryCode(null);
    imageSegment.setImageTargetId(newTargetId);

    NitfWriter writer = new NitfOutputStreamWriter(parseStrategy.getDataSource(), outputStream);
    assertEquals(0, LOGGER.getLoggingEvents().size());
    writer.write();
    assertThat(LOGGER.getLoggingEvents(), is(Arrays.asList(LoggingEvent.error("Could not write", "Cannot generate string target identifier with null country code"))));
}
 
開發者ID:codice,項目名稱:imaging-nitf,代碼行數:26,代碼來源:BasicWriterTest.java

示例15: roundTripFile

import javax.imageio.stream.FileImageInputStream; //導入依賴的package包/類
protected void roundTripFile(String sourceFileName) throws URISyntaxException, NitfFormatException, IOException {
    String outputFile = FilenameUtils.getName(sourceFileName);
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream(sourceFileName)));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);

    NitfParser.parse(reader, parseStrategy);
    NitfWriter writer = new NitfFileWriter(parseStrategy.getDataSource(), outputFile);
    writer.write();
    assertTrue(FileUtils.contentEquals(new File(getClass().getResource(sourceFileName).toURI()), new File(outputFile)));
    assertTrue(new File(outputFile).delete());

    // Do the same again, but with stream writing
    try (
        OutputStream outputStream = new FileOutputStream(outputFile)) {
        writer = new NitfOutputStreamWriter(parseStrategy.getDataSource(), outputStream);
        writer.write();
        assertTrue(FileUtils.contentEquals(new File(getClass().getResource(sourceFileName).toURI()), new File(outputFile)));
    }
    assertTrue(new File(outputFile).delete());
}
 
開發者ID:codice,項目名稱:imaging-nitf,代碼行數:25,代碼來源:AbstractWriterTest.java


注:本文中的javax.imageio.stream.FileImageInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。