java简单截图_简单的java截图程序

主要代码是中间那一段。

1.[代码][Java]代码

import java.awt.image.BufferedImage;

import java.io.File;

import javax.imageio.ImageIO;

public class ImgTool {

private int startX;

private int startY;

private int width;

private int height;

/**

* 源路径

*/

private String srcPath;

/**

* 目标路径

*/

private String tarPath;

public static void main(String args[]){

ImgTool imgT = new ImgTool();

imgT.setStartX(100);

imgT.setStartY(100);

imgT.setHeight(200);

imgT.setWidth(200);

imgT.setSrcPath("农场.jpg");

imgT.setTarPath("d:/1.jpg");

imgT.cut();

}

/**

* 根据开始坐标,宽度和高度切图。

* 把图片读入内存缓冲区,然后再

* 根据具体坐标切取子图最后把子

* 图俺规定的格式存入指定文件

*/

public void cut(){

try {

BufferedImage bufImg = ImageIO.read(new File(srcPath));

bufImg = bufImg.getSubimage(startX, startY, width, height);

ImageIO.write(bufImg,"jpg",new File(tarPath));

} catch (Exception e) {

e.printStackTrace();

}

}

public int getStartX() {

return startX;

}

public void setStartX(int startX) {

this.startX = startX;

}

public int getStartY() {

return startY;

}

public void setStartY(int startY) {

this.startY = startY;

}

public int getWidth() {

return width;

}

public void setWidth(int width) {

this.width = width;

}

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

}

public String getSrcPath() {

return srcPath;

}

public void setSrcPath(String srcPath) {

this.srcPath = srcPath;

}

public String getTarPath() {

return tarPath;

}

public void setTarPath(String tarPath) {

this.tarPath = tarPath;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值