Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving annotations? #28

Open
rsrock opened this issue Jun 22, 2014 · 7 comments
Open

Saving annotations? #28

rsrock opened this issue Jun 22, 2014 · 7 comments

Comments

@rsrock
Copy link
Collaborator

rsrock commented Jun 22, 2014

Is there a way to save an annotated image to a .png, for example?

@timholy
Copy link
Member

timholy commented Jun 22, 2014

I guess we should add a Save as... to the context menu?

@timholy
Copy link
Member

timholy commented Jul 8, 2014

Just to check, do you know you can do this?

Cairo.write_to_png(imgc.c.back, "/tmp/annot.png")

That will write the Canvas exactly as it is (including the padding, if any, to set the aspect ratio) to a file.

@timholy
Copy link
Member

timholy commented Jul 8, 2014

I added some functions to trim the padding: JuliaGraphics/Cairo.jl@98007fc and 35ce5b4. Pkg.update() will get you both updates.

Still probably want to add it to the context menu, so I'll leave this open.

@rsrock
Copy link
Collaborator Author

rsrock commented Jul 11, 2014

Hi Tim,
Was out at a GRC. Did not know this-- thanks for the info and adding the write function.

@rsrock
Copy link
Collaborator Author

rsrock commented Jan 16, 2018

3+ years later, and I'm back 😄. This appears to work now:

function write_to_png(guidict, filename)
    canvas = guidict["gui"]["canvas"]
    ctx = getgc(canvas)
    Cairo.write_to_png(ctx.surface, filename)
end

[edit] Spoke too soon. The getgc sometimes fails with UndefRefError: access to undefined reference. I don't quite understand that one, because I'm calling this after a guidict = imshow(img), and I see the image so the context should be there. I'm starting to get the feeling that I don't know what I'm doing here...

@rsrock
Copy link
Collaborator Author

rsrock commented Jan 17, 2018

Ok, after poking at this for a bit, I'm stumped. The call to getgc() (or drilling into the context field directly) always fails from a test script with UndefRefError: access to undefined reference, and always succeeds from the REPL.

The problem isn't because the window gets destroyed at the end of the script, because the error occurs before then. Adding the bit of code at the end of the README.md to wait on the window close event did not help either.

I've tried adding gc_preserve() calls, but I'm not sure I hit the right incantation. I'm also not sure why they'd be necessary given this line in GtkReactive: https://github.com/JuliaGizmos/GtkReactive.jl/blob/8179c208ff5fa16d6d4879c8dce578cc68eff59b/src/graphics_interaction.jl#L244

Why is my graphic context vaporizing here? Pinging @timholy for desperately needed help!

@szcf-weiya
Copy link

Hi @rsrock , I am wondering if it is possible to save gif/mp4 for movie-like images, i.e., images with the time axis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants