drcj64241 2012-09-14 19:32
浏览 282
已采纳

Golang中的图像处理

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?

Thanks.

  • 写回答

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 (
        "fmt"
        "os"
        "image/draw"
        "image"
        "image/jpeg"
        "code.google.com/p/graphics-go/graphics"
    )
    
    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})
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容