网页生成图片快照

网页生成图片快照

源码地址:https://github.com/juforg/websnapasimg

使用的核心开源项目:

DJNativeSwing 1.0.3

DJNativeSwing-SWT 1.0.3

org.eclipse.swt.win32.win32.x86_64  4.3

调用

请求地址

测试环境:http://localhost:7090/htmlsnapshot/snaphtml
调用方式 GET

参数名说明
htmlUrl需要将response的html进行截图的请求地址,需要URLEncoder.encode(htmlUrl,"UTF-8")
imgType生成图片的类型 如:PNG,GIF,JPG,BMP,RAF

保存返回的图片流

  1. HttpClient client =newHttpClient();
  2. HttpMethod get =newGetMethod("http://localhost:8081/htmlsnapshot/snaphtml?htmlUrl=http%3A%2F%2Fsoa2.yundasys.com%3A8080%2Fydmobile%2Fbpsfinance%2Fzhengzhaosy%2F15346handler57090mbtmp.shtml&imgType=png");
  3. int status =-1;
  4. try{
  5. status = client.executeMethod(get);
  6. if(200== status){
  7. File file =newFile(path);//保存图片至本地的路径
  8. if(!file.getParentFile().exists()){
  9. file.getParentFile().mkdirs();
  10. }
  11. fos =newFileOutputStream(file);
  12. in = get.getResponseBodyAsStream();//获取流
  13. out =newBufferedOutputStream(fos);
  14. int i;
  15. while((i=in.read())!=-1){
  16. out.write(i);
  17. }
  18. out.flush();
  19. out.close();
  20. in.close();
  21. System.out.println("生成文件:"+path);
  22. }
  23. }catch(Exception e){
  24. ;
  25. }finally{//释放资源
  26. get.releaseConnection();
  27. try{
  28. if(null!=out){
  29. out.close();
  30. }
  31. if(null!=in){
  32. in.close();
  33. }
  34. }catch(IOException e){
  35. e.printStackTrace();
  36. }
  37. }





转载于:https://www.cnblogs.com/juforg/p/5027667.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值