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