I am currently using rsvg in Python to separate Svggroups.
I got it working so that rsvg loads a single group ... alas all the transparent space around that still remains.
Is there a gtk functionallity to cut away all this space?
Thanks for all the answers!
There's nothing built-in but it's fairly simple to code it (walk over pixels, find the transparent ones). Unfortunately walking over pixels in python is probably slow.
Related
Is it possible to scale all the items of a pygame program?
I am running the AdvancedDemo from with pygame project:
http://www.pygame.org/project-PaintBrush-1280-.html
But it is too large for my resolution. Is it possible to scale everything that is displayed to fit on the screen, without having to transform all the objects individually?
Thanks
Tom
Not sure how your advance demo works, but you can use
pygame.transform.scale
to scale down the resulting screen. This might be a bit slow though.
I have a GTK drawing area and I want to have an image display as the background for it, while other things can be drawn over it.
My first attempt at this involved me simply taking the image, putting it into a pixmap, and drawing it before I draw other objects. This resulted in the objects backgrounds completely covering my background image.
Now I am thinking I need to change the object's pixmap's gtk.gdk.GC so the background color it has is transparent. Here is where I am having problems. I do not know how to set a gtk.gdk.Color's alpha.
How do I set a gtk.gdk.Color's alpha? (or any other way of making the color transparent)
If this idea seems unlikely to work please let me know. I am pretty new to GTK.
I don't know if this can help you, but my best advice is to use Cairo: an open source 2D graphics library providing cross-platform support for advanced 2D drawing. It is also the easiest way to draw 2D graphics, I think
(I've tried GDK in the past and I thought it was much more tricky to use).
In python you can use the specific bindings Pycairo.
Here you can learn more about it, with easy tutorials.
For your specific problem, see more about images
and trasparency.
The main function for trasparency are:
set_source_rgba(red, green, blue[, alpha=1.0])
paint_with_alpha(alpha)
A great summary to learn how to manage images and transparency is in the example Reflected image in the same page linked before about trasparency.
I have a wx.ScrolledWindow where is drawn on using cairo. I have implemented a zoom-functionality which right now redraws the whole content.
But as there will be up to 200 curves to draw I should consider a more performant solution.
I have thought of these:
Buffering images for the zoom factors -1/+1 (Memory consuming)
Using librsvg and buffer an SVG image (I have read something about this. Does librsvg work under Windows too?)
Storing the cairo.Context after drawing groups of curves, and on zoom restoring it (just an idea.. is that possible?)
Are there other possibilities, and: what is the best solution?
Thanks a lot
Not really a concrete answer to your question, but I was faced with the same problem and just switched to matplotlib where a zoom and pan function is already implemented. I am not sure though if it is super performant. I have the feeling my program was running more smoothly before.
I also tried out floatcanvas and floatcanvas2 but was not really happy with both of them.
If you're double-buffering anyway, why not do a quick bitmap scale as a "preview" while waiting for the newly redrawn vector image? I confess I don't know how to do this. But if you can make it work, it should work! :)
Working on my Major project for software design and development and have run into the hurdle that when using pygame.gfxdraw.aacircle to draw big circles, the output goes screwy as seen here
the window in the picture is showing a section of a circle with a radius of size 1561
if no-one can suggest a fix or alternate way of drawing aa circles i will probably just use the regular circle function as it doesn't look to bad at sch a large radius.
I would suggest not to use pygame.gfxdraw, since it is clearly marked as experimental.
From the documentation:
EXPERIMENTAL!: meaning this api may change, or dissapear in later
pygame releases. If you use this, your
code will break with the next pygame
release.
Just stick with the regular circle function.
EDIT:
Maybe you should open a bugreport on the pygame bugtracker or the pygame mailinglist.
I'm looking for a way to draw smooth animations in Python. I want to use cairo, partly because I like the sub-pixel filtering and partly because I'm familiar with the API. My first approach was to use a GTK.DrawingArea as the target for a cairo surface. While the drawing was quick I couldn't find any reliable way to tie the display / buffering to the vertical sync so the animation was jerky and unreliable.
My next approach was to try PyGame. Using the examples in the wiki as a starting point I've written some simple code to animate various bouncing balls. The different approaches on the linked page fall into two categories:
Draw to an offscreen cairo
ImageSurface and then use Numpy to
convert the pixel buffer to a Pygame
surface.
Share the same memory for both
surfaces
The first approach sucks for performance as the conversion takes about 10ms, which is most of the time-slice that I have for 60hz frames. I'm running the code on a Macbook-pro with 2.2Ghz Core2Duo and an Nvidia 8400. The time is very dependent on the size of the surface, this is for a 800x800 window.
The second approach surfaces from the ordering of pixel coordinates. Both cairo and pygame insist that they can only use RGB pixel ordering and don't support conversion. The problem is that when I setup a pygame surface it uses BGRA pixel ordering, which completely shafts me.
So now for the questions:
Is it possible to change the pixel
format used by either library on the
mac to be compatible with each
other?
If it is not possible what is the
fastest way to do the conversion
purely in Python?
If the fastest Python way still
sucks up most of the time for a
frame then how can I interface to
some C code to do the conversion?
Depending on how complex the
interface to C is, how much point is
there in using pygame instead of
just writing the SDL interface in C?
.
This tutorial also could help you: http://www.pygame.org/wiki/CairoPygame
These may be of help pygame #cairo , squirtle svg pygame
And another thread: SVG rendering in a PyGame application