V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hao123yinlong
V2EX  ›  问与答

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

  •  
  •   hao123yinlong · Mar 31, 2015 · 3121 views
    This topic created in 4048 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
        1
    wohenyingyu01  
       Apr 1, 2015   ❤️ 1
    为什么要自己控制流,直接用bufferedimage类不好么,当时我50毫秒一帧都不卡
    hao123yinlong
        2
    hao123yinlong  
    OP
       Apr 1, 2015
    @wohenyingyu01 我需要获取到图片的byte[]
    hao123yinlong
        3
    hao123yinlong  
    OP
       Apr 1, 2015
    @wohenyingyu01 人眼是24帧呃 。。你20帧会感觉到不流畅的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2513 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:09 · PVG 14:09 · LAX 23:09 · JFK 02:09
    ♥ Do have faith in what you're doing.