96编辑器旗下产品
找图
终身
ID:0
到期时间:永久
退出登录
您的位置:首页 > 百科管理 > 详情

java图片压缩-java 可以压缩gif图片吗?

原创:找图网 2023-04-14 05:40:14
  • java图片压缩比为1

  • java压缩图片,按照比例进行压缩

    public static void main(String[] args) {

    try {

    //图片所在路径

    BufferedImage templateImage = (new File("C:\\Users\\晏丁丁\\Pictures\\图片1.png"));

    //原始图片的长度和宽度

    int height = ();

    int width = ();

    //通过比例压缩

    float scale = 0.5f;

    //通过固定长度压缩

    /*int doWithHeight = 100;

    int dowithWidth = 300;*/

    //压缩之后的长度和宽度

    int doWithHeight = (int) (scale * height);

    int dowithWidth = (int) (scale * width);

    BufferedImage finalImage = new BufferedImage(dowithWidth, doWithHeight, _INT_RGB);

    ().drawImage((dowithWidth, doWithHeight, _SMOOTH), 0, 0, null);

    //图片输出路径,以及图片名

    FileOutputStream fileOutputStream = new FileOutputStream("D:/image/");

    JPEGImageEncoder encoder = (fileOutputStream);

    (finalImage);

    ();

    } catch (IOException e) {

    e.printStackTrace();

    }

    }

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    文章知

  • 如何用java 调整jepg图片压缩

  • ImageWriter writer; // 自己获取 ImageWriter 对象

    ImageWriteParam iwp = ();

    (_EXPLICIT);

    // 参数为0和1

    // 1表示设置最小的压缩以保持最大的图片质量

    (1);

    File file = new File(OUTPUTFILE);

    FileImageOutputStream output = new FileImageOutputStream(file);

    (output);

    IIOImage image = new IIOImage(BUFFEREDIMAGE, null, null);

    // 写入图片

    (null, image, iwp);

    ()

    问了一下我远标教育的哥们,希望对你有用!

  • java 可以压缩gif图片吗?

  • 不可以,目前只有用java转化jpg、png、jpeg格式的文件,gif内部是用帧实现的,不能被压缩。

    最新文章 更多
    最新素材 更多
    公司介绍 网站地图 图片资讯
    Copyright © 2010-2022 山东找图网络科技有限公司  鲁ICP备18007836号-3  邮箱:15653358549@163.com