本文整理匯總了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;
}