Giter Site home page Giter Site logo

annotate's Introduction

图片批注Demo

  • 基于canvas,参考其他已有方案的基础上,封装了可扩展、易修改的模块
  • 集成zrender.js(echarts的渲染驱动),如需扩展本模块需要了解zrender.js相关api
  • 批注模板数据来源为templateData.json,如有需求可修改templateUri、templateGroupUri、templateListUri以及bindSelectReaded方法,使适配后端开发
  • 本模块入参为图片路径以及回调函数,出参为修改后的图片的base64格式,可直接js生成图片,也可传到后端生成图片(需要开放http请求大小限制server.max-http-header-size=10240000)
  • index.html引用
<script src="../jslib/jquery/jquery-2.0.3.js" charset="utf-8"></script>
<script src="../jslib/layui-v2.5.4/layui.all.js" charset="utf-8"></script>
<script src='../jslib/polyfill/promise/promise-polyfill.js' type='text/javascript' charset='utf-8'></script>
<script src='../jslib/canvas/annotate/zrender.js' type='text/javascript' charset='utf-8'></script>
<script src='../jslib/canvas/annotate/annotate.js' type='text/javascript' charset='utf-8'></script>
  • index.html调用方法
annotate.show({
            baseImgUrl: src, //图片路径
            outImg: function (res) {
                //回调函数
            }
        });
  • 基于SpingBoot开发,需要注意获取部署路径的方法,否则不能达到多次批注的效果,只能对原图修改
    private static String detectWebRootPath() {
        try {
            String path = PathKit.class.getResource("/").toURI().getPath();
            if (null == path){
                path = springBootWebRootPath();
                return path;
            }else{
                //return (new File(path)).getParentFile().getParentFile().getCanonicalPath();
                return (new File(path)).getCanonicalPath() + "/static/";
            }
        } catch (Exception var1) {
            throw new RuntimeException(var1);
        }
    }

    private static String springBootWebRootPath(){
        //获取根目录
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (!path.exists()) path = new File("");

        //如果上传目录为/static/images/upload/,则可以如下获取:
        File upload = new File(path.getAbsolutePath(), "static/");
        if (!upload.exists()) upload.mkdirs();
        //在开发测试模式时,得到的地址为:{项目跟目录}/target/static/images/upload/
        //在打包成jar正式发布时,得到的地址为:{发布jar包目录}/static/images/upload/

        return upload.getAbsolutePath();
    }
  • 启动后示例: 启动后示例

annotate's People

Contributors

lyx990593218 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.