當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。