本文整理汇总了Java中javax.imageio.metadata.IIOMetadata类的典型用法代码示例。如果您正苦于以下问题:Java IIOMetadata类的具体用法?Java IIOMetadata怎么用?Java IIOMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IIOMetadata类属于javax.imageio.metadata包,在下文中一共展示了IIOMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
RenderedImage img = image.getRenderedImage();
if (stream == null) {
throw new IOException("Set an output first!");
}
if (param == null) {
param = getDefaultWriteParam();
}
Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
if (param.getSourceRegion() != null) {
sourceRegion = sourceRegion.intersection(param.getSourceRegion());
}
Raster raster = img.getData(sourceRegion);
int quality = 85;
if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
quality = (int) (param.getCompressionQuality() * 100);
}
try {
stream.write(lib.encode(raster, quality).array());
} catch (TurboJpegException e) {
throw new IOException(e);
}
}
示例2: writeImageWithHist
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
protected File writeImageWithHist(BufferedImage bi) throws IOException {
File f = File.createTempFile("hist_", ".png", new File("."));
ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
ImageTypeSpecifier type = new ImageTypeSpecifier(bi);
IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);
/* add hIST node to image metadata */
imgMetadata = upgradeMetadata(imgMetadata, bi);
IIOImage iio_img = new IIOImage(bi,
null, // no thumbnails
imgMetadata);
writer.write(iio_img);
ios.flush();
ios.close();
return f;
}
示例3: doTest
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
private static void doTest(int mode) {
String fileFormat = "bmp";
try {
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix(fileFormat).next();
if(iw == null) {
throw new RuntimeException("No available image writer for "
+ fileFormat
+ " Test failed.");
}
File file = new File("image." + fileFormat);
ImageOutputStream ios = ImageIO.createImageOutputStream(file);
iw.setOutput(ios);
BufferedImage bimg = new BufferedImage(100,
100, BufferedImage.TYPE_INT_RGB);
Graphics g = bimg.getGraphics();
g.setColor(Color.green);
g.fillRect(0,0,100,100);
ImageWriteParam param = iw.getDefaultWriteParam();
param.setCompressionMode(mode);
IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg),
param);
IIOImage iioImg = new IIOImage(bimg, null, meta);
iw.write(null, iioImg, param);
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("Test failed.");
}
}
示例4: main
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public static void main(String[] args) {
ImageWriter w = ImageIO.getImageWritersByFormatName(format).next();
if (w == null) {
throw new RuntimeException("No available writers for format " + format);
}
ImageWriteParam p = w.getDefaultWriteParam();
ImageTypeSpecifier t =
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
IIOMetadata m = w.getDefaultImageMetadata(t, p);
System.out.println("Default image metadata is " + m);
testWritableMetadata(m);
IIOMetadata sm = w.getDefaultStreamMetadata(p);
System.out.println("Default stream metadata is " + sm);
testWritableMetadata(sm);
}
示例5: writeHeader
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
private void writeHeader(IIOMetadata streamMetadata, int bitsPerPixel)
throws IOException {
GIFWritableStreamMetadata sm;
if (streamMetadata instanceof GIFWritableStreamMetadata) {
sm = (GIFWritableStreamMetadata)streamMetadata;
} else {
sm = new GIFWritableStreamMetadata();
Node root =
streamMetadata.getAsTree(STREAM_METADATA_NAME);
sm.setFromTree(STREAM_METADATA_NAME, root);
}
writeHeader(sm.version,
sm.logicalScreenWidth,
sm.logicalScreenHeight,
sm.colorResolution,
sm.pixelAspectRatio,
sm.backgroundColorIndex,
sm.sortFlag,
bitsPerPixel,
sm.globalColorTable);
}
示例6: prepareInsertEmpty
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public void prepareInsertEmpty(int imageIndex,
ImageTypeSpecifier imageType,
int width,
int height,
IIOMetadata imageMetadata,
List<? extends BufferedImage> thumbnails,
ImageWriteParam param) throws IOException {
checkParamsEmpty(imageType, width, height, thumbnails);
this.isInsertingEmpty = true;
SampleModel emptySM = imageType.getSampleModel();
RenderedImage emptyImage =
new EmptyImage(0, 0, width, height,
0, 0, emptySM.getWidth(), emptySM.getHeight(),
emptySM, imageType.getColorModel());
insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
param, false);
}
示例7: getImageMetadata
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
minIndex = imageIndex;
}
System.out.println("Current format class name " + DummyIIOMetadataFormatImpl.class.getName());
return new DummyIIOMetadataImpl(true,
DummyIIOMetadataFormatImpl.nativeMetadataFormatName,
DummyIIOMetadataFormatImpl.class.getName(),
null, null);
}
示例8: main
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
String fileName = "nomarkers.jpg";
String sep = System.getProperty("file.separator");
String dir = System.getProperty("test.src", ".");
String filePath = dir+sep+fileName;
System.out.println("Test file: " + filePath);
File file = new File(filePath);
ImageInputStream stream = ImageIO.createImageInputStream(file);
Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
if(readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(stream);
IIOMetadata metadata = reader.getImageMetadata(0);
IIOMetadataNode standardTree = (IIOMetadataNode)
metadata.getAsTree
(IIOMetadataFormatImpl.standardMetadataFormatName);
IIOMetadataNode colorSpaceType = (IIOMetadataNode)
standardTree.getElementsByTagName("ColorSpaceType").item(0);
String colorSpaceName = colorSpaceType.getAttribute("name");
if(colorSpaceName.equals("RGB"))
throw new RuntimeException("Identified incorrect ColorSpace");
}
}
示例9: getImageMetadata
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public IIOMetadata getImageMetadata(int imageIndex) throws IIOException {
seekToImage(imageIndex);
TIFFImageMetadata im
= new TIFFImageMetadata(imageMetadata.getRootIFD().getTagSetList());
Node root
= imageMetadata.getAsTree(TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME);
im.setFromTree(TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME, root);
return im;
}
示例10: write
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public void write(IIOMetadata sm,
IIOImage iioimage,
ImageWriteParam p) throws IOException {
if (stream == null) {
throw new IllegalStateException("output == null!");
}
if (iioimage == null) {
throw new IllegalArgumentException("iioimage == null!");
}
if (iioimage.hasRaster()) {
throw new UnsupportedOperationException("canWriteRasters() == false!");
}
resetLocal();
GIFWritableStreamMetadata streamMetadata;
if (sm == null) {
streamMetadata =
(GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
} else {
streamMetadata =
(GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
}
write(true, true, streamMetadata, iioimage, p);
}
示例11: readFrom
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
private static ITXtTest readFrom(File f) {
try (ImageInputStream imageInputStream =
ImageIO.createImageInputStream(f)) {
ImageReader r = ImageIO.getImageReaders(imageInputStream).next();
r.setInput(imageInputStream);
IIOImage dst = r.readAll(0, null);
// look for iTXt node
IIOMetadata m = dst.getMetadata();
Node root = m.getAsTree(m.getNativeMetadataFormatName());
Node n = root.getFirstChild();
while (n != null && !"iTXt".equals(n.getNodeName())) {
n = n.getNextSibling();
}
if (n == null) {
throw new RuntimeException("No iTXt node!");
}
ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
return t;
} catch (Throwable e) {
throw new RuntimeException("Reading test failed.", e);
}
}
示例12: getImageMetadata
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public IIOMetadata getImageMetadata(int imageIndex)
throws IOException {
setThreadLock();
try {
// imageMetadataIndex will always be either a valid index or
// -1, in which case imageMetadata will not be null.
// So we can leave checking imageIndex for gotoImage.
if ((imageMetadataIndex == imageIndex)
&& (imageMetadata != null)) {
return imageMetadata;
}
cbLock.check();
gotoImage(imageIndex);
imageMetadata = new JPEGMetadata(false, false, iis, this);
imageMetadataIndex = imageIndex;
return imageMetadata;
} finally {
clearThreadLock();
}
}
示例13: createAnimatedImage
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
ImageWriter writer, File outputFile) {
try {
fos = new FileOutputStream(outputFile);
ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
System.out.println(ios);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
IIOMetadata streamData = writer.getDefaultStreamMetadata(param);
writer.prepareWriteSequence(streamData);
ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
IIOMetadata imgData = writer.convertImageMetadata(
(IIOMetadata) metadata, specify, param);
GIFImageMetadata gifData = setAnimationProperties(imgData);
IIOImage iim = new IIOImage(bi, null, gifData);
param.setProgressiveMode(param.MODE_DISABLED);
writer.writeToSequence(iim, param);
writer.endWriteSequence();
ios.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: test
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
final File file = File.createTempFile("temp", ".img");
file.deleteOnExit();
final FileOutputStream fos = new FileOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
final IIOMetadata data = writer.getDefaultStreamMetadata(null);
if (writer.canWriteSequence()) {
writer.prepareWriteSequence(data);
} else {
try {
writer.prepareWriteSequence(data);
throw new RuntimeException(
"UnsupportedOperationException was not thrown");
} catch (final UnsupportedOperationException ignored) {
// expected
}
}
writer.dispose();
ios.close();
}
示例15: prepareWriteSequence
import javax.imageio.metadata.IIOMetadata; //导入依赖的package包/类
public void prepareWriteSequence(IIOMetadata streamMetadata)
throws IOException {
if (stream == null) {
throw new IllegalStateException("Output is not set.");
}
resetLocal();
// Save the possibly converted stream metadata as an instance variable.
if (streamMetadata == null) {
this.theStreamMetadata =
(GIFWritableStreamMetadata)getDefaultStreamMetadata(null);
} else {
this.theStreamMetadata = new GIFWritableStreamMetadata();
convertMetadata(STREAM_METADATA_NAME, streamMetadata,
theStreamMetadata);
}
this.isWritingSequence = true;
}