2012-09-14 19:32
浏览 273


I have the following:

  1. Background image (bi)
  2. Image1 (i1)
  3. Image3 (i2)

I want to position i1 and i2 over bi with some angle and then produce a final image. I have x and y axis value for i1 and i2 and their expected rotation angle. i1 and i2 may partially overlay on each other. but I have z index for i1 and i2 to know, if in case they overlap then who will be in foreground.

I am trying to achieve this in Golang.
http://golang.org/doc/articles/image_draw.html seems to do this. Anyone knows any similar example of code, that may help. Or can you show me couple of lines in Golang as a pseudo program?


图片转代码服务由CSDN问答提供 功能建议


  1. 背景图片( bi)
  2. 图片1(i1)
  3. 图片3(i2)

    我要放置i1 和i2以一定角度覆盖bi,然后生成最终图像。 我有i1和i2的x和y轴值及其预期的旋转角度。 i1和i2可以部分重叠。 但是我有i1和i2的z索引知道,如果它们重叠,那么谁会在前景。

    < a href =“ http://golang.org/doc/articles/image_draw.html” rel =“ nofollow”> http://golang.org/doc/articles/image_draw.html 似乎可以做到这一点。 任何人都知道任何类似的代码示例,可能会有所帮助。 还是可以向我展示Golang中作为伪程序的几行代码?


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douqihua6212 2012-09-15 02:43

    Not sure exactly what you are looking for and I haven't worked with the image package much at all ... but just following the sample code and using graphics-go package (it works for me), I was able to do something at least.

    package main
    import (
    func main() {
        fImg1, _ := os.Open("arrow1.jpg")
        defer fImg1.Close()
        img1, _, _ := image.Decode(fImg1)
        fImg2, _ := os.Open("arrow2.jpg")
        defer fImg2.Close()
        img2, _, _ := image.Decode(fImg2)
        m := image.NewRGBA(image.Rect(0, 0, 800, 600))
        draw.Draw(m, m.Bounds(), img1, image.Point{0,0}, draw.Src)
        //draw.Draw(m, m.Bounds(), img2, image.Point{-200,-200}, draw.Src)
        graphics.Rotate(m, img2, &graphics.RotateOptions{3.5})
        toimg, _ := os.Create("new.jpg")
        defer toimg.Close()
        jpeg.Encode(toimg, m, &jpeg.Options{jpeg.DefaultQuality})
    打赏 评论

相关推荐 更多相似问题