fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.37k stars 354 forks source link

dc.SavePNG() isn't working - Hello Circle example #132

Closed marktforsyth closed 3 years ago

marktforsyth commented 3 years ago

I really like the look of this library, and I think it will be very helpful in a lot of the things that I want to do. However, I've had some trouble getting it to work, which may easily be because I've misread the documentation or am looking the wrong places.

When I run the "Hello Circle" code (shown below), I get no errors, which is good, however I also don't see any saved image.

package main

import "github.com/fogleman/gg"

func main() {
    dc := gg.NewContext(1000, 1000)
    dc.DrawCircle(500, 500, 400)
    dc.SetRGB(0, 0, 0)
    dc.Fill()
    dc.SavePNG("out.png")
}

Am I simply looking in the wrong place for the image? For example, do they all save in a specific place on my system (I'm using Windows 10), instead of in the directory of my project? I was expecting it to create a file called "out.png" inside my directory, but that hasn't happened, so that's why I'm wondering if it may have saved elsewhere.

In case it's helpful in debugging the issue, here is the layout of my project. As shown, it is very simple right now. Could this issue be happening because I'm not configuring my project properly?

generate-art/
    - main.go
    - go.mod
    - go.sum

Thank you for your help!

marktforsyth commented 3 years ago

As an update, I made some progress on the issue, but I haven't solved it entirely yet.

While reading through the documentation, I noticed that the dc.SavePNG() function returns an error; so, I imported fmt and and changed my final line of code to: fmt.Println(dc.SavePNG("out.png")) to try and shed more light on the issue.

The error that fmt printed was as follows: open out.png: Access is denied.

When I googled that, I found this StackOverflow discussion, which pointed out that it could be an antivirus permissions issue. My computer uses AVG Antivirus Free, which is different than the software mentioned in the discussion, but I still thought that might be relevant. I added C:\Users\Computer\AppData\Local\Temp (and the file path to my specific project) to the exceptions list. However, this didn't fully cover it. Do I need to add more things to my exceptions list?

I also tried running the go run . command from an administrator powershell, but that didn't work either.

Hopefully this provides a little more context in narrowing down the source of the problem.

JoiLa commented 3 years ago

you can try abs path

marktforsyth commented 3 years ago

Thank you for replying so quickly!

I tried changing the url to "./out.png" and "C:/Users/.../generate-art/out.png", however neither of those changed the result. Is this what you meant by abs path, or did I misinterpret your advice (for example, where you referring to a special function that works differently from SavePNG())?

JoiLa commented 3 years ago

Thank you for replying so quickly!

I tried changing the url to "./out.png" and "C:/Users/.../generate-art/out.png", however neither of those changed the result. Is this what you meant by abs path, or did I misinterpret your advice (for example, where you referring to a special function that works differently from SavePNG())?

I am concerned about this project and I am studying! You can debug step by step in golang to see where the error is. hope this helps.

marktforsyth commented 3 years ago

Thanks for all your help. It may be that my computer simply isn't configured quite right to use this library, and if so that's fine --it's not a huge necessity, just something I was experimenting with. So, if you have any more insights, let me know; but don't worry too much about it.