Go获取当前执行路径及图片的加解码
2015-06-24 11:03
417 查看
// imagecode.go package main import ( "bytes" "fmt" "os/exec" "path/filepath" "strings" "image" "image/jpeg" "io/ioutil" "os" ) func main() { //读取一张图片,ff为[]byte类型 ff, _ := ioutil.ReadFile("image1.jpg") //把ff写入文件中 _ = ioutil.WriteFile("./output.jpg.txt", ff, 0666) //新建一个缓存 bbb := bytes.NewBuffer(ff) //对byte进行解码 m, _, _ := image.Decode(bbb) //新建一个文件 f, _ := os.Create("output.jpg") fmt.Println("f name:", f.Name()) defer f.Close() jpeg.Encode(f, m, nil) //获得当前执行路径 str := getCurrentPath() fmt.Println("end:", str) fmt.Println("end:", str+f.Name()) } func getCurrentPath() string { file, _ := exec.LookPath(os.Args[0]) fmt.Println("file:", file) path, _ := filepath.Abs(file) fmt.Println("path:", path) splitstring := strings.Split(path, "\\") size := len(splitstring) splitstring = strings.Split(path, splitstring[size-1]) ret := strings.Replace(splitstring[0], "\\", "/", size-1) return ret }
相关文章推荐
- edx---Mongo,could not connect to localhost:27017:
- Google Chrome浏览器调试功能介绍
- HDU 1533 Going Home(最小费用流)
- Django permission
- google play SDK 游戏排行榜的接入分享
- [Leetcode] Basic Calculator
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
- goagent安装和使用
- Django文件上传
- GOF设计模式
- 20150427( Django,filter)
- com.Goods.ForEach
- Go学习1: Hello world
- [django]项目打包构建
- [django]项目打包构建
- uva 11090 Going in Cycle!! (求平均权值最小的环路)
- The last packet sent successfully to the server was 0 milliseconds ago
- goldengate一些参数整理
- 移除整个GoldenGate文件夹之后的恢复
- 利用未公开API获取终端会话闲置时间(Idle Time)和登入时间(Logon Time)