本文整理匯總了Java中javax.imageio.spi.ImageReaderSpi.canDecodeInput方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageReaderSpi.canDecodeInput方法的具體用法?Java ImageReaderSpi.canDecodeInput怎麽用?Java ImageReaderSpi.canDecodeInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.spi.ImageReaderSpi
的用法示例。
在下文中一共展示了ImageReaderSpi.canDecodeInput方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doTest
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
public void doTest(ImageReaderSpi spi) throws IOException {
System.out.println("Test for " + title +
(canDecode ? " (can decode)" : " (can't decode)"));
System.out.print("As a stream...");
ImageInputStream iis =
ImageIO.createImageInputStream(getDataStream());
if (spi.canDecodeInput(iis) != canDecode) {
throw new RuntimeException("Test failed: wrong decideion " +
"for stream data");
}
System.out.println("OK");
System.out.print("As a file...");
iis = ImageIO.createImageInputStream(getDataFile());
if (spi.canDecodeInput(iis) != canDecode) {
throw new RuntimeException("Test failed: wrong decideion " +
"for file data");
}
System.out.println("OK");
}
示例2: filter
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
public boolean filter(Object elt) {
try {
ImageReaderSpi spi = (ImageReaderSpi)elt;
ImageInputStream stream = null;
if (input instanceof ImageInputStream) {
stream = (ImageInputStream)input;
}
// Perform mark/reset as a defensive measure
// even though plug-ins are supposed to take
// care of it.
boolean canDecode = false;
if (stream != null) {
stream.mark();
}
canDecode = spi.canDecodeInput(input);
if (stream != null) {
stream.reset();
}
return canDecode;
} catch (IOException e) {
return false;
}
}
示例3: filter
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
public boolean filter(Object provider)
{
if (provider instanceof ImageReaderSpi)
{
ImageReaderSpi spi = (ImageReaderSpi) provider;
try
{
if (spi.canDecodeInput(object))
return true;
}
catch (IOException e)
{
// Return false in this case
}
}
return false;
}
示例4: read
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
/**
* Create a buffered image from an image input stream. An image
* reader that supports the given image data is automatically
* selected from the collection of registered readers. If no
* registered reader can handle the input format, null is returned.
*
* @param stream the image input stream from which to read image
* data
*
* @return a new buffered image created from the given image data,
* or null
*
* @exception IllegalArgumentException if stream is null
* @exception IOException if a reading error occurs
*/
public static BufferedImage read(ImageInputStream stream)
throws IOException
{
if (stream == null)
throw new IllegalArgumentException("null argument");
Iterator providers = getRegistry().getServiceProviders(ImageReaderSpi.class, true);
while (providers.hasNext())
{
ImageReaderSpi spi = (ImageReaderSpi) providers.next();
if (spi.canDecodeInput(stream))
{
ImageReader reader = spi.createReaderInstance();
reader.setInput(stream);
return reader.read(0, null);
}
}
return null;
}
示例5: main
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
public static void main(String[] args) {
IOException expectedException = null;
TestStream iis = new TestStream();
ImageReader wbmp = ImageIO.getImageReadersByFormatName("WBMP").next();
if (wbmp == null) {
System.out.println("No WBMP reader: skip the test");
return;
}
ImageReaderSpi spi = wbmp.getOriginatingProvider();
iis.checkPosition();
try {
spi.canDecodeInput(iis);
} catch (IOException e) {
expectedException = e;
}
if (expectedException == null) {
throw new RuntimeException("Test FAILED: stream was not used");
}
iis.checkPosition();
System.out.println("Test PASSED");
}
示例6: filter
import javax.imageio.spi.ImageReaderSpi; //導入方法依賴的package包/類
public boolean filter(Object elt) {
try {
ImageReaderSpi spi = (ImageReaderSpi)elt;
ImageInputStream stream = null;
if (input instanceof ImageInputStream) {
stream = (ImageInputStream)input;
}
// Perform mark/reset as a defensive measure
// even though plug-ins are supposed to take
// care of it.
boolean canDecode = false;
if (stream != null) {
stream.mark();
}
try {
canDecode = spi.canDecodeInput(input);
} finally {
if (stream != null) {
stream.reset();
}
}
return canDecode;
} catch (IOException e) {
return false;
}
}