zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    tkinter_战队数据查询系统
    python_tkinter组件
    python_tkinter基本属性
    python_tkinter组件摆放方式
    python_推导式
    python_装饰器
    python_模块1
    python_生成随机验证码
    linux基础_使用指令3
    linux部署django项目流程(全)
  • 原文地址:https://www.cnblogs.com/luwei0915/p/15271799.html
Copyright © 2011-2022 走看看