本文整理汇总了Java中javax.imageio.ImageIO.getImageReadersByMIMEType方法的典型用法代码示例。如果您正苦于以下问题:Java ImageIO.getImageReadersByMIMEType方法的具体用法?Java ImageIO.getImageReadersByMIMEType怎么用?Java ImageIO.getImageReadersByMIMEType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageIO
的用法示例。
在下文中一共展示了ImageIO.getImageReadersByMIMEType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chooseImageFormat
import javax.imageio.ImageIO; //导入方法依赖的package包/类
public static String chooseImageFormat(String[] formats) {
if (formats == null || formats.length == 0)
return null;
for (String s : formatOrderPreference) {
for (String f : formats) {
if (f.equalsIgnoreCase(s)) {
Iterator it = ImageIO.getImageReadersByMIMEType(f);
if (it.hasNext())
return f;
}
}
}
System.err.println("No image recoginized, using " + formats[0]);
return formats[0]; // none recognized; just use the first in the caps list
}
示例2: isReadable
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private boolean isReadable(MediaType mediaType) {
if (mediaType == null) {
return true;
}
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
return imageReaders.hasNext();
}
示例3: read
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
ImageInputStream imageInputStream = null;
ImageReader imageReader = null;
try {
imageInputStream = createImageInputStream(inputMessage.getBody());
MediaType contentType = inputMessage.getHeaders().getContentType();
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
process(irp);
imageReader.setInput(imageInputStream, true);
return imageReader.read(0, irp);
}
else {
throw new HttpMessageNotReadableException(
"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
}
finally {
if (imageReader != null) {
imageReader.dispose();
}
if (imageInputStream != null) {
try {
imageInputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
}
示例4: testGetReaderMIMETypes
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static void testGetReaderMIMETypes() {
String[] types = ImageIO.getReaderMIMETypes();
for (String t : types) {
Iterator<ImageReader> it = ImageIO.getImageReadersByMIMEType(t);
if (!it.hasNext()) {
throw new RuntimeException("getReaderMIMETypes returned " +
"an unknown type: " + t);
}
}
}
示例5: testReaderIsRegistered
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Test
public void testReaderIsRegistered() {
Supplier<Iterator<ImageReader>> getReaderIter = () -> ImageIO.getImageReadersBySuffix("jpg");
assertThat(getReaderIter.get()).isNotEmpty();
assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
getReaderIter = () -> ImageIO.getImageReadersByMIMEType("image/jpeg");
assertThat(getReaderIter.get()).isNotEmpty();
assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
getReaderIter = () -> ImageIO.getImageReadersByFormatName("jpeg");
assertThat(getReaderIter.get()).isNotEmpty();
assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
}