当前位置: 首页>>代码示例>>Java>>正文


Java ImageIO.getImageWritersByMIMEType方法代码示例

本文整理汇总了Java中javax.imageio.ImageIO.getImageWritersByMIMEType方法的典型用法代码示例。如果您正苦于以下问题:Java ImageIO.getImageWritersByMIMEType方法的具体用法?Java ImageIO.getImageWritersByMIMEType怎么用?Java ImageIO.getImageWritersByMIMEType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.ImageIO的用法示例。


在下文中一共展示了ImageIO.getImageWritersByMIMEType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setDefaultContentType

import javax.imageio.ImageIO; //导入方法依赖的package包/类
/**
 * Sets the default {@code Content-Type} to be used for writing.
 * @throws IllegalArgumentException if the given content type is not supported by the Java Image I/O API
 */
public void setDefaultContentType(MediaType defaultContentType) {
	Assert.notNull(defaultContentType, "'contentType' must not be null");
	Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(defaultContentType.toString());
	if (!imageWriters.hasNext()) {
		throw new IllegalArgumentException(
				"Content-Type [" + defaultContentType + "] is not supported by the Java Image I/O API");
	}

	this.defaultContentType = defaultContentType;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:BufferedImageHttpMessageConverter.java

示例2: isWritable

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private boolean isWritable(MediaType mediaType) {
	if (mediaType == null || MediaType.ALL.equals(mediaType)) {
		return true;
	}
	Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(mediaType.toString());
	return imageWriters.hasNext();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:BufferedImageHttpMessageConverter.java

示例3: print

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public Base64Data print(Image v) {
    ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx();
    XMLSerializer xs = XMLSerializer.getInstance();

    String mimeType = xs.getXMIMEContentType();
    if(mimeType==null || mimeType.startsWith("image/*"))
        // because PNG is lossless, it's a good default
        //
        // mime type can be a range, in which case we can't just pass that
        // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming
        // the default of PNG. Not sure if this is complete.
        mimeType = "image/png";

    try {
        Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType);
        if(itr.hasNext()) {
            ImageWriter w = itr.next();
            ImageOutputStream os = ImageIO.createImageOutputStream(imageData);
            w.setOutput(os);
            w.write(convertToBufferedImage(v));
            os.close();
            w.dispose();
        } else {
            // no encoder
            xs.handleEvent(new ValidationEventImpl(
                ValidationEvent.ERROR,
                Messages.NO_IMAGE_WRITER.format(mimeType),
                xs.getCurrentLocation(null) ));
            // TODO: proper error reporting
            throw new RuntimeException("no encoder for MIME type "+mimeType);
        }
    } catch (IOException e) {
        xs.handleError(e);
        // TODO: proper error reporting
        throw new RuntimeException(e);
    }
    Base64Data bd = new Base64Data();
    imageData.set(bd,mimeType);
    return bd;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:RuntimeBuiltinLeafInfoImpl.java

示例4: testGetWriterMIMETypes

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static void testGetWriterMIMETypes() {
    String[] types = ImageIO.getWriterMIMETypes();
    for (String t : types) {
        Iterator<ImageWriter> it = ImageIO.getImageWritersByMIMEType(t);
        if (!it.hasNext()) {
            throw new RuntimeException("getWriterMIMETypes returned " +
                                       "an unknown type: " + t);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:GetReaderWriterInfo.java

示例5: writeImage

import javax.imageio.ImageIO; //导入方法依赖的package包/类
/**
 * Write buffered image as required format
 *
 * @param bi
 * @param mimeType
 * @return
 * @throws IOException
 */
public byte[] writeImage(BufferedImage bi, String mimeType) throws IOException {
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
    if (writers.hasNext()) {
        ImageWriter writer = writers.next();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writer.setOutput(ImageIO.createImageOutputStream(baos));
        writer.write(bi);
        return baos.toByteArray();
    }
    throw new IOException("Cannot write to this mimetype");
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:20,代码来源:StandardImageHandler.java

示例6: write

import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Override
public void write(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
		contentType = getDefaultContentType();
	}
	Assert.notNull(contentType,
			"Count not determine Content-Type, set one using the 'defaultContentType' property");
	outputMessage.getHeaders().setContentType(contentType);
	ImageOutputStream imageOutputStream = null;
	ImageWriter imageWriter = null;
	try {
		imageOutputStream = createImageOutputStream(outputMessage.getBody());
		Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(contentType.toString());
		if (imageWriters.hasNext()) {
			imageWriter = imageWriters.next();
			ImageWriteParam iwp = imageWriter.getDefaultWriteParam();
			process(iwp);
			imageWriter.setOutput(imageOutputStream);
			imageWriter.write(null, new IIOImage(image, null, null), iwp);
		}
		else {
			throw new HttpMessageNotWritableException(
					"Could not find javax.imageio.ImageWriter for Content-Type [" + contentType + "]");
		}
	}
	finally {
		if (imageWriter != null) {
			imageWriter.dispose();
		}
		if (imageOutputStream != null) {
			try {
				imageOutputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:BufferedImageHttpMessageConverter.java

示例7: getPlatformMappingsForFlavor

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (int i = 0; i < mimeTypes.length; i++) {
                Iterator writers =
                    ImageIO.getImageWritersByMIMEType(mimeTypes[i]);

                while (writers.hasNext()) {
                    ImageWriter imageWriter = (ImageWriter)writers.next();
                    ImageWriterSpi writerSpi =
                        imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                        writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mimeTypes[i]);
                        break;
                    }
                }
            }
        }
    } else if (DataTransferer.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataTransferer.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:XDataTransferer.java

示例8: getPlatformMappingsForFlavor

import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Override
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataFlavorUtil.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (String mime : mimeTypes) {
                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mime);
                while (writers.hasNext()) {
                    ImageWriter imageWriter = writers.next();
                    ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                            writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mime);
                        break;
                    }
                }
            }
        }
    } else if (DataFlavorUtil.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataFlavorUtil.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:XDataTransferer.java

示例9: isMimeTypeWritable

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public boolean isMimeTypeWritable(String mimeType) {
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
    return writers.hasNext();
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:5,代码来源:StandardImageHandler.java


注:本文中的javax.imageio.ImageIO.getImageWritersByMIMEType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。