zoukankan      html  css  js  c++  java
  • 网页生成图片快照

    网页生成图片快照

    源码地址: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. }





  • 相关阅读:
    10.31JS日记
    10.24JS日记
    10.23JS日记
    10.22JS日记
    10.19JS日记
    10.18JS日记
    Tomcat—Bad Request
    2016年上半年总结
    线程间操作无效
    压缩字符串的函数
  • 原文地址:https://www.cnblogs.com/juforg/p/5027667.html
Copyright © 2011-2022 走看看