Kivy Image Child Class Produces Two Images
<p>I think this is probably a simple miss understanding about something deeper in kivy, but I have an RoundedImage class that is producing two images, where one is the original without rounded corners and one with the rounded corners off screen a bit. Whats going on?</p>

<p>Screenshot:
<a href="http://imgur.com/gallery/IRYfr" rel="nofollow">http://imgur.com/gallery/IRYfr</a></p>

<p>I think it may be something to do with subclassing Image?</p>

<pre><code>class RoundedImage(Image,StyleUnit):

    _styleist = RadialGradientStyleist    
    _radius = [20]
    _source = ''
    _style = None
    def __init__(self,**kwargs):

        super(RoundedImage,self).__init__(**kwargs)
        #self._source = source
        #self.initalizeStyle()

        with self.canvas:
            StencilPush()
            self.m_rect = RoundedRectangle( size = self.norm_image_size , \
                                            pos=self.center, \
                                            radius=self._radius)
            StencilUse()
            self.rect = Rectangle(  size = self.norm_image_size , \
                                    pos = self.center, \
                                    texture = self.texture)
            StencilUnUse()
            StencilPop()
            #Color(1,1,1)
            #self.line = Line(   rounded_rectangle=self.pos+self.size+self._radius,
            #        width=10)


        self.bind(pos = self.update_rect,
                  size = self.update_rect)

    def update_rect(self,*args):
        self.m_rect.pos = self.center
        self.m_rect.size = self.norm_image_size
        self.rect.pos = self.center
        self.rect.size = self.norm_image_size
</code></pre>

<p>The application code is simple:</p>

<pre><code>class ProfilesApp(App):

    def build(self):
       profile = RoundedImage( source = source,#self.imageLocation,\
                                    allow_stretch=True)
       return profile

profileApp = ProfilesApp()
profileApp.run()
</code></pre>

<p>Ok so this ended up being an issue of not removing a mask in the stencil instructions.</p>

<p>I ended up adding this to the .kv definition for the RoundedRectangle</p>

<pre><code>'''
&lt;-RoundedImage&gt;:
canvas:
Color:
rgb: self.color
StencilPush
RoundedRectangle:
size: self.norm_image_size
pos: self.center[0] - self.norm_image_size[0]/2.0,self.center[1] - self.norm_image_size[1]/2.0
radius: self._radius
StencilUse
Rectangle:
texture: self.texture
size: self.norm_image_size
pos: self.center[0] - self.norm_image_size[0]/2.0,self.center[1] - self.norm_image_size[1]/2.0
StencilUnUse
RoundedRectangle:
size: self.norm_image_size
pos: self.center[0] - self.norm_image_size[0]/2.0,self.center[1] - self.norm_image_size[1]/2.0
radius: self._radius
StencilPop

'''
</code></pre>

python image canvas graphics kivy