zoukankan      html  css  js  c++  java
  • 小程序中获取图片主色

    
    
    let imageSrc = that.swiperList[index].picUrl;
    that.setBackgroundColor(imageSrc, index);


    setBackgroundColor(imageSrc,index) { console.log(imageSrc,
    'imageSrc'); const ctx = wx.createCanvasContext('myCanvas') const that = this wx.getImageInfo({ src: imageSrc, success: function (res) { const poster = res.path ctx.drawImage(poster, 0, 0, 150, 100) ctx.draw(false, () => { wx.canvasToTempFilePath({ x: 0, y: 0, 150, height: 100, destWidth: 150, destHeight: 100, canvasId: "myCanvas", success(res) { console.log(imageSrc, '11111'); let tempPath = res.tempFilePath // 这种方式获取canvas区域隐含的像素数据 wx.canvasGetImageData({ canvasId: 'myCanvas', x: 0, y: 0, 150, height: 100, success(res) { const imageData = res.data // 分区块,可以拓展性的求主要色板,用来做palette let resImageObj = getMainColor(imageData) const { defaultRGB } = resImageObj const { r, g, b } = defaultRGB let resBackground = `rgb(${r}, ${g}, ${b})`; // 图片主色 //that.picMainColor.push({ // sort: index, // background: resBackground //}); //wx.setStorageSync("picMainColor", that.picMainColor); //let item = that.picMainColor.find(e=>e.sort == 0); //that.SET_BACKGROUND_COLOR(item ? item.background : 'rgb(80, 135, 203)'); }, }) }, fail() { console.log('222222'); throw new Error() } }) }) }, fail(err) { console.log(err, '3333'); } }) },
  • 相关阅读:
    洛谷 P1939 矩阵加速(数列)
    【模板】矩阵快速幂
    洛谷 P3128 [USACO15DEC]最大流Max Flow
    洛谷 P1967 货车运输
    【模板】最近公共祖先(LCA)
    【模板】高斯消元法
    java从基础知识(七)java集合
    java基础知识(六)日期处理
    java基础知识(五)java类
    会员体系-系统豆的获取与消费
  • 原文地址:https://www.cnblogs.com/chenwan1218/p/14964244.html
Copyright © 2011-2022 走看看