普通网友 2018-09-28 15:28
浏览 64
已采纳

如何传递magickW和功能参考

May I know how to pass imagick.MagickWand struct to functions and apply it methods on it? It seems that the imagick.NewMagickWand return the type of *imagick.MagickWand, isn't it?

I can't get it done, keep getting the error message: ERROR_WAND: ContainsNoImages `MagickWand-0'.

How to pass proper struct reference to the function so that the mw can be continuously used in those functions?

func generateImage() error {
    // skip error handling
    var err error 

    mw := imagick.NewMagickWand()
    defer mw.Destroy()

    err = createCanvas(mw, "red") // create canvas
    err = compositeIcon(mw, "c:/icon.png") // add icon
    err = addText(mw, "Hello world") // add text

    err = mw.WriteImage("c:/output") // get the output
}

func createCanvas(mw *imagick.MagickWand, color string) error {
    // skip error handling
    var err error
    pw := imagick.NewPixelWand()
    defer pw.Destroy()

    pw.SetColor("blue")
    err = mw.NewImage(200, 100, pw)
    return nil
}

May please help? Newbie here. :)


Update:

The example that I gave is correct. Passing by reference is done correctly in the example above, I received the error because I overlook my code and debug the wrong lines. Sorry for confusion.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongre6270 2018-09-28 15:36
    关注

    If mw has type *imagick.MagickWand then *mw has type imagick.MagickWand.

    That is to say, mw is a pointer to that type and the * operator dereferences the pointer to the type itself.

    mw := imagick.NewMagickWand() // Now mw is a *imagick.MagickWand
    *mw // Is a imagick.MagickWand
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题