dsgdfg30210 2016-08-11 05:52
浏览 51
已采纳

Php和Canvas像素颜色替换[关闭]

Hello dear people of internet,

I have an idea for interesting script, but I'm trying to find the best way to accomplish what I want.

Idea is simple. Have pixels colors replaced, to achieve custom color for character every time. I have this guy, I will be using php canvas and maybe svg to generate these images: source image

enter image description here

And what I basically need is via script turn it into this: final result

enter image description here

I considered few ways to do it:

1) Have alpha only pixels and color it from behind and place alpha image on top to achieve shading and depth

2) Draw each pixel individually (but this option isn't what I really want to do)

3) Use some thing like hue/saturation, but that is beyond my knowledge.

maybe there is something I can do to achieve it.

Thank you.

  • 写回答

1条回答 默认 最新

  • duanming7833 2016-08-11 06:28
    关注

    It's past 2am so here's a brief answer.

    Best option: Create a spritesheet with all your character variations and cut out desired sprites from your spritesheet like this: drawImage(spritesheet, spriteX, spriteY, spriteWidth, spriteHeight, canvasX, canvasY, spriteWidth, spriteHeight)

    Next best option: Create a spritesheet with your full character and then have multiple sets of replacement pants (just pants--not the full character), replacement shirts, replacement weapons, etc. First draw the full character and then draw the desired pants on top of the character -- overwriting the original pants with desired pants. This way you're effectively "dressing" the character in replaceable pants, shirts, weapons, etc.

    If you need runtime recoloring, use compositing to dynamically recolor a cutout of just the pants:

    • Create a full character on the main canvas
    • On a second canvas, create just the pants.
    • Set `secondContext.globalCompositeOperation='source-in'
    • Set a desired fillStyle.
    • Fill a rectangle on the entire second canvas: secondContext.fillRect(0,0,secondCanvas.width,secondCanvas.height)

    About your #2: Expensive to manipulate pixels -- avoid if possible.

    About your #3: If you're just replacing a single RGB color, you don't need to mess with saturation & lightness.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化