hao123yinlong
V2EX  ›  问与答

Java 关于获取 BufferedImage 对象的 Bytes 效率问题

  •  
  •   hao123yinlong · Mar 31, 2015 · 3403 views
    This topic created in 4242 days ago, the information mentioned may be changed or developed.
    代码及运行结果:
    log4j.info(System.currentTimeMillis()); //1427811014567
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    log4j.info(System.currentTimeMillis()); //1427811014567
    ImageIO.write(payOrderImg, "jpg", byteArrayOutputStream);
    log4j.info(System.currentTimeMillis()); //1427811014578
    imgBytes = byteArrayOutputStream.toByteArray();
    log4j.info(System.currentTimeMillis()); //1427811014578

    ImageIO.write(RenderedImage im,
    String formatName,
    OutputStream output) 数据量在20k,耗时11毫秒,速度太慢啦,请大神分析为何会这么慢,另请分享下解决方案
    3 replies  •  2015-04-01 10:01:36 +08:00
    wohenyingyu01
    wohenyingyu01
    Apr 1, 2015❤️1
    1
    为什么要自己控制流,直接用bufferedimage类不好么,当时我50毫秒一帧都不卡
    hao123yinlong
    hao123yinlong
    OP
    Apr 1, 2015
    2
    @wohenyingyu01 我需要获取到图片的byte[]
    hao123yinlong
    hao123yinlong
    OP
    Apr 1, 2015
    3
    @wohenyingyu01 人眼是24帧呃 。。你20帧会感觉到不流畅的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1129 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:01 · PVG 02:01 · LAX 10:01 · JFK 13:01
    ♥ Do have faith in what you're doing.