中文汉字注音,汉字转拼音,支持图片识别文字,支持结果转图下载,附上小程序核心源码

来源:原创 发布时间:2020-06-05 17:23:47 作者:Mos 阅读量:8517

“文字注音”小程序在微信、字节跳动、支付宝、QQ等小程序平台同步上线,微信、头条、抖音、支付宝、QQ中搜索“文字注音”即可获得。

一、功能

汉字转拼音,支持图片识别文字,支持结果转图下载。该款小程序能够轻松将文字注音后输出,无需授权,无需注册,即来即用。你还可以用它来识别图片中的文字后注音,或者随时拍照后识别文字再注音。同时支持注音完成后复制拼音,支持将结果保存成图片下载到手机本地。欢迎扫描下面的各平台得小程序码来尝试一下。

1
2

二、平台小程序码

10
11
12
微信小程序
抖音/头条小程序
QQ小程序

三、核心源码:

源码请关注微信公众号【八四七】,回复3获取:

7

部分源码预览:

save:function(){
    var _that = this;
    _that.down = true;
    //先设置canvas得高度
    _that.canvasHeight = _that.canvasStaticHeight;
    _that.showCanvas = true;
    setTimeout(function(){
        var ctx = uni.createCanvasContext("canvas",_that);
        ctx.rect(0, 0, _that.canvasWidth, _that.canvasHeight);
        ctx.setFillStyle('white');
        ctx.fill();
        ctx.setFillStyle('black');
        // 字体大小
        ctx.setFontSize(14);
        var fontHeight = 14;
        // 宽度
        var width = _that.canvasWidth;
        // 横向间隔
        var transverse = 9;
        // 纵向小间隔
        var portraitSmall = 4;
        // 纵向大间隔
        var portraitBig = 7;
        // 外间距
        var padding = 20;
        // 横向距离累计
        var transverseCumulative = padding;
        // 纵向距离累计
        var portraitCumulative  = padding;
        var lineHeight = portraitSmall  + portraitBig + (fontHeight*2);
        for(var i=0;i<_that.list.length;i++){
            // canvas高度变化
            if(i==0){
                _that.canvasHeight = portraitCumulative + lineHeight;
                setTimeout(function(){},10);
            }
            var item = _that.list[i];
            var metrics = ctx.measureText(item.pinyin);
            var tempX = transverseCumulative + transverse + metrics.width;
            if(tempX > (width-padding) || item.pinyin=="enter"){
                transverseCumulative = padding;
                portraitCumulative = portraitCumulative + lineHeight;
                _that.canvasHeight = portraitCumulative + lineHeight;
                setTimeout(function(){},10);
            }
            if(item.pinyin!="enter"){
                var x1;
                if(transverseCumulative==padding){
                    x1 = transverseCumulative;
                }else{
                    x1 = transverseCumulative + transverse;
                }
                var y1 = portraitCumulative;
                ctx.fillText(item.pinyin, x1, y1);
                var x2 = x1;
                var y2 = y1 + portraitSmall + fontHeight;
                ctx.fillText(item.value,x2, y2);
                transverseCumulative = x1 + metrics.width;
            }
        }
        ctx.draw();
        setTimeout(function(){
            uni.canvasToTempFilePath({
                width: _that.canvasWidth,
                height:  _that.canvasHeight,
                destWidth: _that.canvasWidth * _that.pixelRatio,
                destHeight:  _that.canvasHeight * _that.pixelRatio,
                canvasId: 'canvas',
                success: function(res) {
                uni.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success:function(){
                        uni.showToast({
                            title:"保存成功"
                        })
                    },
                    complete:function(){
                        _that.showCanvas = false;
                        _that.down = false;
                    }
                });
                },
                fail:function(e){
                    console.log(e);
                _that.showCanvas = false;
                _that.down = false;
                }
            })
        },100);
    },100);
}


支付宝打赏 微信打赏
©2021 i847.cn
部分内容转自网络,如有损害您的权益,致邮联系:jiang2008wen#126.com,一经证实,立即删除!     我要留言
备案号:蜀ICP备18020563号-1