dqlxtv1452 2017-09-20 21:16
浏览 88
已采纳

去画在图像蒙版上

I am trying to draw over an image using a template, the template image is the following

enter image description here

I want to colorize the image red, green, blue and yellow colors with custom colors and achieve something like this:

enter image description here

In order to achieve this I currently use this image as a base

enter image description here

And then draw over the template using draw.Draw(outfitImage, outfitImage.Bounds(), generatorImage, image.ZP, draw.Over)

This however gives a very weird result (nothing near the expected result), this is how I replace pixels

func paintPixels(img *image.NRGBA, base color.Color, dst color.Color) {
    br, bg, bb, ba := base.RGBA()
    dr, dg, db, _ := dst.RGBA()
    for x := 0; x < img.Bounds().Dx(); x++ {
        for y := 0; y < img.Bounds().Dy(); y++ {
            r, g, b, a := img.At(x, y).RGBA()
            if br == r && bg == g && bb == b && ba == a {
                img.Set(x, y, color.RGBA{uint8(dr), uint8(dg), uint8(db), 255})
            }
        }
    }
}

enter image description here

The result can vary depending on the alpha value I use when colorizing the image template. So I cant think of a way to achieve the expected result, I guess I should use a mask with draw.DrawMask but I have no clue where to start or how to achieve the result I am looking for

  • 写回答

1条回答 默认 最新

  • duanji1902 2017-09-20 22:13
    关注

    You look like you're just replacing pixels with the colour if all components match. If you look at the compositing methods in bild/blend you should find one that suits you for combining images - you probably want Opacity or Multiply modes and could extract code from this file:

    https://github.com/anthonynsimon/bild/blob/master/blend/blend.go

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

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应