java图像_Java调整大小图像

java图像

Today we will look into java resize image program. Recently I had to upload a lot of images to an FTP server but the images size were huge. Since I was going to use them only on web pages, it was wise to resize them to a smaller size and then upload it.

今天,我们将研究java调整大小图像程序。 最近,我不得不将很多图像上传到FTP服务器,但是图像尺寸很大。 由于我只打算在网页上使用它们,因此明智的做法是将它们调整为较小的大小然后上传。

A few days back I provided a list of online tools to reduce image size. But when you have hundreds of images, it’s better to invest some time and write a program that does this work for you. So let’s see how we can resize an image in java.

几天前,我提供了一些在线工具以减小图像大小 。 但是,当您拥有数百张图像时,最好花一些时间并编写一个可以为您工作的程序。 因此,让我们看看如何在Java中调整图像大小。

Java调整大小图像 (Java Resize Image)

We can use java.awt.Graphics2D class to resize image in java.

我们可以使用java.awt.Graphics2D类来调整Java中图像的大小。

Below is the program that searches all the files in a directory and resizes them to the given size and saves it to a different directory.

以下是搜索目录中所有文件并将其大小调整为给定大小并将其保存到其他目录的程序。

The sample program here saves images in both PNG and JPG format but you can easily change it to serve your specific requirement.

这里的示例程序将图像保存为PNG和JPG格式,但是您可以轻松地对其进行更改以满足您的特定要求。

Java图像调整程序 (Java Image Resize Program)

package com.journaldev.util;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
/**
 * This class will resize all the images in a given folder
 * @author pankaj
 *
 */
public cla
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值