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


Java ImageWriterSpi.canEncodeImage方法代码示例

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


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

示例1: filter

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
public boolean filter(Object provider)
{
  if (provider instanceof ImageWriterSpi)
    {
      ImageWriterSpi spi = (ImageWriterSpi) provider;

      if (spi.canEncodeImage(type))
        {
          String[] formatNames = spi.getFormatNames();
          for (int i = formatNames.length - 1; i >= 0; --i)
            if (formatName.equals(formatNames[i]))
              return true;
        }
    }

  return false;
}
 
开发者ID:vilie,项目名称:javify,代码行数:18,代码来源:ImageIO.java

示例2: canEncodeImage

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
/** Checks that the provided <code>ImageWriter</code> can encode
 * the provided <code>ImageTypeSpecifier</code> or not.  If not, an
 * <code>IIOException</code> will be thrown.
 * @param writer The provided <code>ImageWriter</code>.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:ImageUtil.java

示例3: canEncodeImage

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
/** Checks that the provided {@code ImageWriter} can encode
 * the provided {@code ImageTypeSpecifier} or not.  If not, an
 * {@code IIOException} will be thrown.
 * @param writer The provided {@code ImageWriter}.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ImageUtil.java

示例4: canEncodeImage

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
protected boolean canEncodeImage(int compression, ImageTypeSpecifier imgType) {
    ImageWriterSpi spi = this.getOriginatingProvider();
    if (!spi.canEncodeImage(imgType)) {
        return false;
    }
    int biType = imgType.getBufferedImageType();
    int bpp = imgType.getColorModel().getPixelSize();
    if (compressionType == BI_RLE4 && bpp != 4) {
        // only 4bpp images can be encoded as BI_RLE4
        return false;
    }
    if (compressionType == BI_RLE8 && bpp != 8) {
        // only 8bpp images can be encoded as BI_RLE8
        return false;
    }
    if (bpp == 16) {
        /*
         * Technically we expect that we may be able to
         * encode only some of SinglePixelPackedSampleModel
         * images here.
         *
         * In addition we should take into account following:
         *
         * 1. BI_RGB case, according to the MSDN description:
         *
         *     The bitmap has a maximum of 2^16 colors. If the
         *     biCompression member of the BITMAPINFOHEADER is BI_RGB,
         *     the bmiColors member of BITMAPINFO is NULL. Each WORD
         *     in the bitmap array represents a single pixel. The
         *     relative intensities of red, green, and blue are
         *     represented with five bits for each color component.
         *
         * 2. BI_BITFIELDS case, according ot the MSDN description:
         *
         *     Windows 95/98/Me: When the biCompression member is
         *     BI_BITFIELDS, the system supports only the following
         *     16bpp color masks: A 5-5-5 16-bit image, where the blue
         *     mask is 0x001F, the green mask is 0x03E0, and the red mask
         *     is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
         *     is 0x001F, the green mask is 0x07E0, and the red mask is
         *     0xF800.
         */
        boolean canUseRGB = false;
        boolean canUseBITFIELDS = false;

        SampleModel sm = imgType.getSampleModel();
        if (sm instanceof SinglePixelPackedSampleModel) {
            int[] sizes =
                ((SinglePixelPackedSampleModel)sm).getSampleSize();

            canUseRGB = true;
            canUseBITFIELDS = true;
            for (int i = 0; i < sizes.length; i++) {
                canUseRGB       &=  (sizes[i] == 5);
                canUseBITFIELDS &= ((sizes[i] == 5) ||
                                    (i == 1 && sizes[i] == 6));
            }
        }

        return (((compressionType == BI_RGB) && canUseRGB) ||
                ((compressionType == BI_BITFIELDS) && canUseBITFIELDS));
    }
    return true;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:65,代码来源:BMPImageWriter.java

示例5: filter

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
public boolean filter(Object elt) {
    ImageWriterSpi spi = (ImageWriterSpi)elt;
    return Arrays.asList(spi.getFormatNames()).contains(formatName) &&
        spi.canEncodeImage(type);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:ImageIO.java

示例6: getPlatformMappingsForFlavor

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的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

示例7: getPlatformMappingsForFlavor

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的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

示例8: test

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
public boolean test() throws IIOException, IOException {

        ir.reset();
        iw.reset();

        String[] suffixes = iw.getOriginatingProvider().getFileSuffixes();

        IIOMetadata md = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);

        System.out.println("Image type " + img.getType());

        ImageWriterSpi spi = iw.getOriginatingProvider();
        boolean bCanEncode = spi.canEncodeImage(img);

        System.out.println("Can encode image? " + (bCanEncode ? "YES" : "NO"));
        if (!bCanEncode) {
            return true;
        }
        IIOImage iio_img = new IIOImage(img, null, md);

        String fname = "test"+img.getType()+"."+suffixes[0];

        iw.setOutput(ImageIO.createImageOutputStream(new FileOutputStream(new File(fname))));
        System.out.print("write image ... ");
        iw.write(iio_img);
        System.out.println("OK");
        System.out.print("read image ... ");

        byte[] ba_image = baos.toByteArray();

        ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);

        ir.setInput(ImageIO.createImageInputStream(new FileInputStream(new File(fname))));

        BufferedImage res = ir.read(0);
        System.out.println("OK");

        System.out.print("compare images ... ");
        boolean r = compare(img,res);
        System.out.println(r?"OK":"FAILED");
        return r;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:BMPPluginTest.java

示例9: imageToStandardBytesImpl

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
byte[] imageToStandardBytesImpl(RenderedImage renderedImage,
                                          String mimeType)
    throws IOException {

    Iterator<ImageWriter> writerIterator = ImageIO.getImageWritersByMIMEType(mimeType);

    ImageTypeSpecifier typeSpecifier =
        new ImageTypeSpecifier(renderedImage);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOException ioe = null;

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

        if (!writerSpi.canEncodeImage(typeSpecifier)) {
            continue;
        }

        try {
            try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(baos)) {
                imageWriter.setOutput(imageOutputStream);
                imageWriter.write(renderedImage);
                imageOutputStream.flush();
            }
        } catch (IOException e) {
            imageWriter.dispose();
            baos.reset();
            ioe = e;
            continue;
        }

        imageWriter.dispose();
        baos.close();
        return baos.toByteArray();
    }

    baos.close();

    if (ioe == null) {
        ioe = new IOException("Registered service providers failed to encode "
                              + renderedImage + " to " + mimeType);
    }

    throw ioe;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:48,代码来源:DataTransferer.java

示例10: imageToStandardBytesImpl

import javax.imageio.spi.ImageWriterSpi; //导入方法依赖的package包/类
protected byte[] imageToStandardBytesImpl(RenderedImage renderedImage,
                                          String mimeType)
    throws IOException {

    Iterator writerIterator = ImageIO.getImageWritersByMIMEType(mimeType);

    ImageTypeSpecifier typeSpecifier =
        new ImageTypeSpecifier(renderedImage);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOException ioe = null;

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

        if (!writerSpi.canEncodeImage(typeSpecifier)) {
            continue;
        }

        try {
            ImageOutputStream imageOutputStream =
                ImageIO.createImageOutputStream(baos);
            try {
                imageWriter.setOutput(imageOutputStream);
                imageWriter.write(renderedImage);
                imageOutputStream.flush();
            } finally {
                imageOutputStream.close();
            }
        } catch (IOException e) {
            imageWriter.dispose();
            baos.reset();
            ioe = e;
            continue;
        }

        imageWriter.dispose();
        baos.close();
        return baos.toByteArray();
    }

    baos.close();

    if (ioe == null) {
        ioe = new IOException("Registered service providers failed to encode "
                              + renderedImage + " to " + mimeType);
    }

    throw ioe;
}
 
开发者ID:JetBrains,项目名称:jdk8u_jdk,代码行数:52,代码来源:DataTransferer.java


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