Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

探讨:关于小程序绘制模糊的最优解决方法。 #3

Open
hairyf opened this issue Dec 9, 2020 · 2 comments
Open

探讨:关于小程序绘制模糊的最优解决方法。 #3

hairyf opened this issue Dec 9, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@hairyf
Copy link
Owner

hairyf commented Dec 9, 2020

关于小程序绘制并生成图片后模糊的解决方法,目前最好的解决方法是当绘制一个600*400的海报,则放大一倍尺寸为1200*800,但这种方法使得每次定义尺寸或者偏移值时,都得计算一遍(num*2)

例如:

    dp.canvas.width = 300 * 2;
    dp.canvas.height = 300 * 2;
    dp.draw((ctx) => {
      ctx.fillStyle = "#fff";
      ctx.fillRect(0, 0, 300 * 2, 300 * 2);
    });

又或者:

    const st2 = (size) => size * 2;
    dp.canvas.width = st2(300);
    dp.canvas.height = st2(300);
    dp.draw((ctx) => {
      ctx.fillStyle = "#fff";
      ctx.fillRect(0, 0, st2(300) st2(300);
    });

在我看来,无论是哪种方法,都使工作量大量的增加,目前有个想法,就是使用Object.defineProperty和来new Proxy动态的修改内容。

例如:

    dp.canvas.width = 300; // dp.canvas.width = 600
    dp.canvas.height = 300;  // dp.canvas.width = 600
    dp.draw((ctx) => {
      ctx.fillStyle = "#fff";
      ctx.fillRect(0, 0, 300, 300);  // ctx.fillRect(0, 0, 600, 600)
    });

但这无疑会增加影响先有api的稳定性,并且在一些特定场景就会出现不合理的情况。

    dp.canvas.width = 300; // dp.canvas.width = 600
    dp.canvas.height = 300;  // dp.canvas.width = 600
    dp.draw((ctx) => {
      ctx.fillStyle = "#fff";
      ctx.fillRect(0, 0, dp.canvas.width, dp.canvas.height);  // ctx.fillRect(0, 0, 1200, 1200)
    });

在此,如何更好的解决图片模糊的问题?

@hairyf hairyf added the enhancement New feature or request label Dec 9, 2020
@hairyf hairyf changed the title 探讨:关于小程序绘制模糊的解决方法的最优解决方法。 探讨:关于小程序绘制模糊的最优解决方法。 Dec 9, 2020
@Dunqing
Copy link

Dunqing commented Dec 23, 2021

scale放大

@waylonzheng
Copy link

const multi = 3 dp.canvas.width = multi*dp.canvas.width dp.canvas.height = multi*dp.canvas.height dp.ctx.scale(multi, multi)

同上,scale可以解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants