Creating a Mask for an Image to use for rotation

Image.Rotate: " If the image has a mask, then the mask colour is used
for the uncovered pixels in the rotated image background. Otherwise,
black will be used as the fill colour."

import wx

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="blarf")
        self.image = wx.Image('sv.png')

        if not self.image.HasAlpha():
            self.image.InitAlpha()
        self.image.ConvertAlphaToMask()

        img = self.image.Rotate(45, (50, 50))
        #self.image = wx.BitmapFromImage(img)

        if not img.HasAlpha():
            img.InitAlpha()
        img.ConvertAlphaToMask()

# img = shape.image.ConvertToImage()
        img.SaveFile("test.jpg", wx.BITMAP_TYPE_JPEG)

app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()

The saved image has a black 'rotation rectangle' around the image.

How do I go about creating a suitable mask for any image that a user may
load? I don't want to choose a colour myself, e.g. white
cheers

···

--
Steven Sproat, BSc
http://whyteboard.org/

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

R, G, B = image.FindFirstUnusedColour()
     # or GetOrFindMaskColour perhaps
     image.SetMaskColour(R, G, B)

···

On 5/6/10 11:35 PM, Steven Sproat wrote:

Image.Rotate: " If the image has a mask, then the mask colour is used
for the uncovered pixels in the rotated image background. Otherwise,
black will be used as the fill colour."

The saved image has a black 'rotation rectangle' around the image.

How do I go about creating a suitable mask for any image that a user may
load? I don't want to choose a colour myself, e.g. white

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Robin Dunn wrote:

Image.Rotate: " If the image has a mask, then the mask colour is used
for the uncovered pixels in the rotated image background. Otherwise,
black will be used as the fill colour."

The saved image has a black 'rotation rectangle' around the image.

How do I go about creating a suitable mask for any image that a user may
load? I don't want to choose a colour myself, e.g. white

    R, G, B = image.FindFirstUnusedColour()
    # or GetOrFindMaskColour perhaps
    image.SetMaskColour(R, G, B)

Hi Rob,

I'm still getting the black fill in the "rectangle" of the rotation.

import wx

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="blarf")
        self.image = wx.Image('sv.png')

        R, G, B = self.image.GetOrFindMaskColour()
        self.image.SetMaskColour(R, G, B)
        img = self.image.Rotate(45, (50, 50))

        img.SaveFile("test.jpg", wx.BITMAP_TYPE_JPEG)

app = wx.App()
frame = Frame()
frame.Show()
app.MainLoop()

one fix is to save as PNG but that creates some very large files
compared to JPGs (in photographs, for example)

···

On 5/6/10 11:35 PM, Steven Sproat wrote:

--
Steven Sproat, BSc

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Sorry, I didn't notice that you were using JPEG before. The JPEG image file format does not support saving masks or alpha channel information, so the mask colour chosen by wx.Image is just being written to the file as that colour.

···

On 5/7/10 11:46 AM, Steven Sproat wrote:

Robin Dunn wrote:

On 5/6/10 11:35 PM, Steven Sproat wrote:

Image.Rotate: " If the image has a mask, then the mask colour is used
for the uncovered pixels in the rotated image background. Otherwise,
black will be used as the fill colour."

The saved image has a black 'rotation rectangle' around the image.

How do I go about creating a suitable mask for any image that a user may
load? I don't want to choose a colour myself, e.g. white

     R, G, B = image.FindFirstUnusedColour()
     # or GetOrFindMaskColour perhaps
     image.SetMaskColour(R, G, B)

Hi Rob,

I'm still getting the black fill in the "rectangle" of the rotation.

one fix is to save as PNG but that creates some very large files
compared to JPGs (in photographs, for example)

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Robin Dunn wrote:

···

On 5/7/10 11:46 AM, Steven Sproat wrote:

Robin Dunn wrote:

On 5/6/10 11:35 PM, Steven Sproat wrote:

Image.Rotate: " If the image has a mask, then the mask colour is used
for the uncovered pixels in the rotated image background. Otherwise,
black will be used as the fill colour."

The saved image has a black 'rotation rectangle' around the image.

How do I go about creating a suitable mask for any image that a
user may
load? I don't want to choose a colour myself, e.g. white

     R, G, B = image.FindFirstUnusedColour()
     # or GetOrFindMaskColour perhaps
     image.SetMaskColour(R, G, B)

Hi Rob,

I'm still getting the black fill in the "rectangle" of the rotation.

one fix is to save as PNG but that creates some very large files
compared to JPGs (in photographs, for example)

Sorry, I didn't notice that you were using JPEG before. The JPEG
image file format does not support saving masks or alpha channel
information, so the mask colour chosen by wx.Image is just being
written to the file as that colour.

ah alright then, thank you. I think I'll stick to white, then.
Cheers again, hopefully I can get my new version of my program released
this weekend - I've been stuck with this problem for a long time.

All the best,

--
Steven Sproat, BSc

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en