白沐沐vccc 2022-05-09 20:02 采纳率: 96.7%
浏览 875
已结题

java中ImageIO.write()参数含义

请问ImageIO.write(image, "bmg", filWriterOne);括号里的三个参数分别代表说明意思?

img

  • 写回答

1条回答 默认 最新

  • kkjt0130 2022-05-10 16:40
    关注

    image:图片对象
    "bmg" :图片格式
    , filWriterOne 需要写入的地方
    源码中有三个方法

      /**
         * Writes an image using the an arbitrary <code>ImageWriter</code>
         * that supports the given format to an
         * <code>ImageOutputStream</code>.  The image is written to the
         * <code>ImageOutputStream</code> starting at the current stream
         * pointer, overwriting existing stream data from that point
         * forward, if present.
         *
         * <p> This method <em>does not</em> close the provided
         * <code>ImageOutputStream</code> after the write operation has completed;
         * it is the responsibility of the caller to close the stream, if desired.
         *
         * @param im a <code>RenderedImage</code> to be written.
         * @param formatName a <code>String</code> containing the informal
         * name of the format.
         * @param output an <code>ImageOutputStream</code> to be written to.
         *
         * @return <code>false</code> if no appropriate writer is found.
         *
         * @exception IllegalArgumentException if any parameter is
         * <code>null</code>.
         * @exception IOException if an error occurs during writing.
         */
        public static boolean write(RenderedImage im,
                                    String formatName,
                                    ImageOutputStream output) throws IOException {
            if (im == null) {
                throw new IllegalArgumentException("im == null!");
            }
            if (formatName == null) {
                throw new IllegalArgumentException("formatName == null!");
            }
            if (output == null) {
                throw new IllegalArgumentException("output == null!");
            }
    
            return doWrite(im, getWriter(im, formatName), output);
        }
    
        /**
         * Writes an image using an arbitrary <code>ImageWriter</code>
         * that supports the given format to a <code>File</code>.  If
         * there is already a <code>File</code> present, its contents are
         * discarded.
         *
         * @param im a <code>RenderedImage</code> to be written.
         * @param formatName a <code>String</code> containing the informal
         * name of the format.
         * @param output a <code>File</code> to be written to.
         *
         * @return <code>false</code> if no appropriate writer is found.
         *
         * @exception IllegalArgumentException if any parameter is
         * <code>null</code>.
         * @exception IOException if an error occurs during writing.
         */
        public static boolean write(RenderedImage im,
                                    String formatName,
                                    File output) throws IOException {
            if (output == null) {
                throw new IllegalArgumentException("output == null!");
            }
            ImageOutputStream stream = null;
    
            ImageWriter writer = getWriter(im, formatName);
            if (writer == null) {
                /* Do not make changes in the file system if we have
                 * no appropriate writer.
                 */
                return false;
            }
    
            try {
                output.delete();
                stream = createImageOutputStream(output);
            } catch (IOException e) {
                throw new IIOException("Can't create output stream!", e);
            }
    
            try {
                return doWrite(im, writer, stream);
            } finally {
                stream.close();
            }
        }
    
        /**
         * Writes an image using an arbitrary <code>ImageWriter</code>
         * that supports the given format to an <code>OutputStream</code>.
         *
         * <p> This method <em>does not</em> close the provided
         * <code>OutputStream</code> after the write operation has completed;
         * it is the responsibility of the caller to close the stream, if desired.
         *
         * <p> The current cache settings from <code>getUseCache</code>and
         * <code>getCacheDirectory</code> will be used to control caching.
         *
         * @param im a <code>RenderedImage</code> to be written.
         * @param formatName a <code>String</code> containing the informal
         * name of the format.
         * @param output an <code>OutputStream</code> to be written to.
         *
         * @return <code>false</code> if no appropriate writer is found.
         *
         * @exception IllegalArgumentException if any parameter is
         * <code>null</code>.
         * @exception IOException if an error occurs during writing.
         */
        public static boolean write(RenderedImage im,
                                    String formatName,
                                    OutputStream output) throws IOException {
            if (output == null) {
                throw new IllegalArgumentException("output == null!");
            }
            ImageOutputStream stream = null;
            try {
                stream = createImageOutputStream(output);
            } catch (IOException e) {
                throw new IIOException("Can't create output stream!", e);
            }
    
            try {
                return doWrite(im, getWriter(im, formatName), stream);
            } finally {
                stream.close();
            }
        }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月18日
  • 已采纳回答 5月10日
  • 创建了问题 5月9日

悬赏问题

  • ¥15 kali安装包如何解决,请给明确方案和步骤
  • ¥15 DEA软件进行企业创新效率的计算
  • ¥15 树莓派驱动42步进电机
  • ¥20 bevfusion mit可视化遇到的问题
  • ¥15 如何获得《人工智能工程技术人员》认证?
  • ¥100 悬赏破解EFS加密,速度
  • ¥30 用MATLAB画随t变化的函数图像,式中包含了累加求和,出现报错,不知道怎么办了,请解释一下
  • ¥200 求破解MFS加密,悬赏
  • ¥15 博弈论两人分100元问题
  • ¥20 求指导,stm32串口控制程序无法编译