Saving annotations?
Is there a way to save an annotated image to a .png, for example?
I guess we should add a Save as... to the context menu?
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.
I added some functions to trim the padding: https://github.com/JuliaLang/Cairo.jl/commit/98007fca91c49f911770cb08f1aa01346ae32c24 and 35ce5b4aa9ac5b34daa5adf8c27316c79629d573. Pkg.update() will get you both updates.
Still probably want to add it to the context menu, so I'll leave this open.
Hi Tim, Was out at a GRC. Did not know this-- thanks for the info and adding the write function.
3+ years later, and I'm back :smile:. 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...
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!
Hi @rsrock , I am wondering if it is possible to save gif/mp4 for movie-like images, i.e., images with the time axis.