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

21 篇文章 0 订阅
12 篇文章 0 订阅

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

一、功能

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

12

二、平台小程序码

345
微信小程序抖音/头条小程序QQ小程序

三、核心源码:

原文链接:https://www.i847.cn/article/3033.html

部分源码预览:

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);
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

imooos

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值