duanjingwei7239 2013-08-16 18:28
浏览 72
已采纳

开始-尝试创建.pgm文件,但最终得到一个二进制文件

I'm reading a pgm-file in order to apply some filter to it and rewrite the result to a new pgm-file. However, I always end up with a binary file (vim doesn't show the values but stuff like ^G ^0 ^K etc, the file-command tells me it's a data file and imagemagick can't open the file)

The code where I write to the file looks like this:

fd,err := os.Create(filename)
wr := bufio.NewWriter(fd)
//img is of type [][]int and holds the values to be written
str := "P2
" + filename + "
" + string(len(img[0])) + ...
if _,err := wr.WriteString(outStr); err != nil {..}

and then some more of that in a loop where I go through the img array.

What am I missing here?

  • 写回答

1条回答 默认 最新

  • dongque5529 2013-08-16 18:45
    关注

    string(len(img[0])) doesn't do what you're trying to do here. You need strconv.Itoa

    string(len(img[0])) is creating a single character string containing whichever character is the Unicode code point for len(img[0]) (see the spec section on conversions)

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料