本文整理汇总了Java中javax.imageio.stream.ImageInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ImageInputStream类的具体用法?Java ImageInputStream怎么用?Java ImageInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageInputStream类属于javax.imageio.stream包,在下文中一共展示了ImageInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPictureSize
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
/**
* Extracts the picture size of a given Image.
*
* @param path Path to the image
* @return Image-size in pixel
* @throws IOException Throws exception when file-access fails
*/
public static Dimension getPictureSize(final String path) throws IOException {
try (ImageInputStream in = ImageIO.createImageInputStream(path)) {
final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
if (readers.hasNext()) {
ImageReader reader = readers.next();
try {
reader.setInput(in);
return new Dimension(reader.getWidth(0), reader.getHeight(0));
} finally {
reader.dispose();
}
}
return null;
}
}
示例2: addImageExtension
import javax.imageio.stream.ImageInputStream; //导入依赖的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;
}
示例3: canDecodeInput
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
public boolean canDecodeInput(Object input) throws IOException {
if (!(input instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)input;
byte[] b = new byte[8];
stream.mark();
stream.readFully(b);
stream.reset();
return (b[0] == (byte)137 &&
b[1] == (byte)80 &&
b[2] == (byte)78 &&
b[3] == (byte)71 &&
b[4] == (byte)13 &&
b[5] == (byte)10 &&
b[6] == (byte)26 &&
b[7] == (byte)10);
}
示例4: closeQuietly
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
/**
* Close an {@link ImageInputStream} unconditionally. Equivalent to
* calling <code>s.close()</code> when <code>s</code> is nonnull.
* {@link IOException}s are quietly logged, as there is generally
* nothing that can be done about exceptions on closing.
*
* @param s a (possibly <code>null</code>) <code>ImageInputStream</code>
*/
// Why doesn't ImageInputStream implement Closeable? Argh!
public static void closeQuietly(ImageInputStream s) {
if (s == null) return;
try {
s.close();
}
catch (IOException e) {
// ignore
// Note that ImageInputStreamImpl.close() rather ridiculously throws
// an IOException if the stream is already closed. This is always done
// via ImageInputStreamImpl.checkClosed().
}
}
示例5: main
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
createTestFile();
ImageInputStream iis = ImageIO.createImageInputStream(file);
r = ImageIO.getImageReaders(iis).next();
iis.close();
for (int i = 0; i < MAX_THREADS; i++) {
(new ConcurrentReadingTest()).start();
}
// wait for started threads
boolean needWait = true;
while (needWait) {
Thread.sleep(100);
synchronized(lock) {
needWait = completeCount < MAX_THREADS;
}
}
System.out.println("Test PASSED.");
}
示例6: F2IR
import javax.imageio.stream.ImageInputStream; //导入依赖的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;
}
示例7: runTest
import javax.imageio.stream.ImageInputStream; //导入依赖的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);
}
示例8: TestImageReaderSpi
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
public TestImageReaderSpi(String[] FORMATNAMES, String[] SUFFIXES,
String[] MIMETYPES) {
super("J Duke", // vendor
"1.0", // version
FORMATNAMES, // format names
SUFFIXES, // file suffixes
MIMETYPES, // mimetypes
"readTest.TestImageReader", // reader class name
new Class<?>[] { ImageInputStream.class }, // input types
null, // writer class names.
true, // supports native metadata,
null, // [no] native stream metadata format
null, // [no] native stream metadata class
null, // [no] native extra stream metadata format
null, // [no] native extra stream metadata class
true, // supports standard metadata,
null, // metadata format name,
null, // metadata format class name
null, // [no] extra image metadata format
null // [no] extra image metadata format class
);
}
示例9: read
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
/**
* Returns a <code>BufferedImage</code> as the result of decoding
* a supplied <code>ImageInputStream</code> with an
* <code>ImageReader</code> chosen automatically from among those
* currently registered. If no registered
* <code>ImageReader</code> claims to be able to read the stream,
* <code>null</code> is returned.
*
* <p> Unlike most other methods in this class, this method <em>does</em>
* close the provided <code>ImageInputStream</code> after the read
* operation has completed, unless <code>null</code> is returned,
* in which case this method <em>does not</em> close the stream.
*
* @param stream an <code>ImageInputStream</code> to read from.
*
* @return a <code>BufferedImage</code> containing the decoded
* contents of the input, or <code>null</code>.
*
* @exception IllegalArgumentException if <code>stream</code> is
* <code>null</code>.
* @exception IOException if an error occurs during reading.
*/
public static BufferedImage read(ImageInputStream stream)
throws IOException {
if (stream == null) {
throw new IllegalArgumentException("stream == null!");
}
Iterator iter = getImageReaders(stream);
if (!iter.hasNext()) {
return null;
}
ImageReader reader = (ImageReader)iter.next();
ImageReadParam param = reader.getDefaultReadParam();
reader.setInput(stream, true, true);
BufferedImage bi;
try {
bi = reader.read(0, param);
} finally {
reader.dispose();
stream.close();
}
return bi;
}
示例10: main
import javax.imageio.stream.ImageInputStream; //导入依赖的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);
}
}
示例11: createInputStreamInstance
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
public ImageInputStream createInputStreamInstance(Object input,
boolean useCache,
File cacheDir)
throws IOException {
if (input instanceof InputStream) {
InputStream is = (InputStream)input;
if (useCache) {
return new FileCacheImageInputStream(is, cacheDir);
} else {
return new MemoryCacheImageInputStream(is);
}
} else {
throw new IllegalArgumentException();
}
}
示例12: canDecodeInput
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
@Override
public boolean canDecodeInput(Object input) throws IOException {
if (!(input instanceof ImageInputStream)) {
input = ImageIO.createImageInputStream(input);
}
if (input == null) {
return false;
}
ImageInputStream stream = (ImageInputStream)input;
byte[] b = new byte[12];
try {
stream.mark();
stream.readFully(b);
} catch (IOException e) {
return false;
}
return Arrays.equals(b, HEADER_MAGIC);
}
示例13: setInput
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
public void setInput(Object input,
boolean seekForwardOnly,
boolean ignoreMetadata)
{
setThreadLock();
try {
cbLock.check();
super.setInput(input, seekForwardOnly, ignoreMetadata);
this.ignoreMetadata = ignoreMetadata;
resetInternalState();
iis = (ImageInputStream) input; // Always works
setSource(structPointer);
} finally {
clearThreadLock();
}
}
示例14: getThumbnail
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
int index,
JPEGImageReader reader) throws IOException {
reader.thumbnailStarted(index);
BufferedImage ret = null;
if ((thumb != null) && (index == 0)) {
ret = thumb.getThumbnail(iis, reader);
} else {
if (thumb != null) {
index--;
}
JFIFExtensionMarkerSegment jfxx =
(JFIFExtensionMarkerSegment) extSegments.get(index);
ret = jfxx.thumb.getThumbnail(iis, reader);
}
reader.thumbnailComplete();
return ret;
}
示例15: readByteBuffer
import javax.imageio.stream.ImageInputStream; //导入依赖的package包/类
void readByteBuffer(ImageInputStream iis,
byte [] data,
JPEGImageReader reader,
float workPortion,
float workOffset) throws IOException {
int progInterval = Math.max((int)(data.length/20/workPortion),
1);
for (int offset = 0;
offset < data.length;) {
int len = Math.min(progInterval, data.length-offset);
iis.read(data, offset, len);
offset += progInterval;
float percentDone = ((float) offset* 100)
/ data.length
* workPortion + workOffset;
if (percentDone > 100.0F) {
percentDone = 100.0F;
}
reader.thumbnailProgress (percentDone);
}
}