本文整理汇总了Java中javax.imageio.stream.ImageInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java ImageInputStream.read方法的具体用法?Java ImageInputStream.read怎么用?Java ImageInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.stream.ImageInputStream
的用法示例。
在下文中一共展示了ImageInputStream.read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: canDecodeInput
import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
if (!(source instanceof ImageInputStream)) {
return false;
}
ImageInputStream iis = (ImageInputStream) source;
iis.mark();
// If the first two bytes are a JPEG SOI marker, it's probably
// a JPEG file. If they aren't, it definitely isn't a JPEG file.
int byte1 = iis.read();
int byte2 = iis.read();
iis.reset();
if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) {
return true;
}
return false;
}
示例3: getThumbnail
import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
BufferedImage getThumbnail(ImageInputStream iis,
JPEGImageReader reader)
throws IOException {
iis.mark();
iis.seek(streamPos);
// read the palette
byte [] palette = new byte [PALETTE_SIZE];
float palettePart = ((float) PALETTE_SIZE) / getLength();
readByteBuffer(iis,
palette,
reader,
palettePart,
0.0F);
DataBufferByte buffer = new DataBufferByte(thumbWidth*thumbHeight);
readByteBuffer(iis,
buffer.getData(),
reader,
1.0F-palettePart,
palettePart);
iis.read();
iis.reset();
IndexColorModel cm = new IndexColorModel(8,
256,
palette,
0,
false);
SampleModel sm = cm.createCompatibleSampleModel(thumbWidth,
thumbHeight);
WritableRaster raster =
Raster.createWritableRaster(sm, buffer, null);
return new BufferedImage(cm,
raster,
false,
null);
}
示例4: canDecodeInput
import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public boolean canDecodeInput(Object source) throws IOException {
if (!(source instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)source;
stream.mark();
try {
byte[] sig = new byte[4];
stream.read(sig);
return sig[0]=='S' && sig[1]=='I' && sig[2]=='M' && sig[3]=='P';
} finally {
stream.reset();
}
}
示例5: bufferFromStream
import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
private ByteBuffer bufferFromStream(ImageInputStream stream) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
final byte[] buf = new byte[8192];
int n;
while (0 < (n = stream.read(buf))) {
bos.write(buf, 0, n);
}
return ByteBuffer.wrap(bos.toByteArray());
}