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

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日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理