• canvas_26 画图像


    <template>
        <view class="zcvs">
    
            <view class="zcvs-item">
                <view>画图像</view>
                <view>
                    <canvas canvas-id="cvs" id="cvs" style=" 400px; height: 400px;border: 1px solid #007AFF;" />
                </view>
            </view>
    
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {
    
                };
            },
            onReady() {
                this.drawCvs();
            },
            methods: {
                drawCvs() {
    
                    // 画画布
                    let pixList = [];
                    for (let i = 0; i < 200; i++) {
                        pixList.push(...[234, 67, 53, 255])
                    }
                    const data = new Uint8ClampedArray(pixList);
                    uni.canvasPutImageData({
                        canvasId: 'cvs',
                        x: 200,
                        y: 200,
                         pixList.length / 4,
                        data: data,
                        success(res) {
                            console.log("像素写入画布成功!");
                        }
                    })
    
                    // 读画布
                    uni.canvasGetImageData({
                        canvasId: "cvs",
                        x: 200,
                        y: 200,
                         pixList.length / 4,
                        height: 1,
                        success(res) {
                            console.log(res.width) // 200
                            console.log(res.height) // 1
                            console.log(res.data instanceof Uint8ClampedArray) // true
                            console.log(res.data.length) // 200 * 1 * 4
    
                            let data = res.data;
                            for (var i = 0; i < data.length; i += 4) {
                                var red = data[i]; // red
                                var green = data[i + 1]; // green
                                var blue = data[i + 2]; // blue
                                // i+3 就是 alpha 值
                                console.log("颜色是:", red, green, blue);
                            }
    
                        }
                    })
                },
            }
        }
    </script>
    
    <style lang="scss" scoped>
    
    </style>
  • 相关阅读:
    numpy的文件存储 .npy .npz 文件
    Google词向量word2vec的使用
    Python函数-logging.basicConfig
    现货黄金-20180918
    Pandas的loc方法
    Pandas的index属性
    python调用exe程序
    Pandas的concat方法
    转载:为什么选择Nginx(1.2)《深入理解Nginx》(陶辉)
    discuz3.4:在Centos6.5中安装过程
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15271799.html
Copyright © 2020-2023  润新知