Images: colors to grayscale conversion

Hi
I load a png from file and display it on a device context:

image = wx.Image("myimage.png")
bmp = wx.BitmapFromImage(image)
dc.DrawBitmap(bmp, x, y, True)

Is there a way to draw a grayscale version of that image?
Thanks for any tip
Fabio

you could do a pingpong with PIL like this :slight_smile:

def convertToGrayscale(img):
     import Image, ImageOps
     orig = Image.new("RGB", img.GetSize())
     orig.fromstring(img.GetData())
     pil = ImageOps.grayscale(pil)
     ret = wx.EmptyImage(pil.size[0], pil.size[1])
     ret.SetData(pil.convert('RGB').tostring())
     return ret

Peter.

···

On Thu, 07 Apr 2005 18:52:45 +0300, jfabio <jfmlimcv@yahoo.it> wrote:

Hi
I load a png from file and display it on a device context:

image = wx.Image("myimage.png")
bmp = wx.BitmapFromImage(image)
dc.DrawBitmap(bmp, x, y, True)

Is there a way to draw a grayscale version of that image?
Thanks for any tip
Fabio

Thanks Peter, your help has resolved my problem.
Thanks again!
Fabio

Peter Damoc wrote:

···

On Thu, 07 Apr 2005 18:52:45 +0300, jfabio <jfmlimcv@yahoo.it> wrote:

Hi
I load a png from file and display it on a device context:

image = wx.Image("myimage.png")
bmp = wx.BitmapFromImage(image)
dc.DrawBitmap(bmp, x, y, True)

Is there a way to draw a grayscale version of that image?
Thanks for any tip
Fabio

you could do a pingpong with PIL like this :slight_smile:

def convertToGrayscale(img):
    import Image, ImageOps
    orig = Image.new("RGB", img.GetSize())
    orig.fromstring(img.GetData())
    pil = ImageOps.grayscale(pil)
    ret = wx.EmptyImage(pil.size[0], pil.size[1])
    ret.SetData(pil.convert('RGB').tostring())
    return ret

Peter.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

You're welcome!
Pay it forward.

Peter

···

On Fri, 08 Apr 2005 11:21:46 +0300, jfabio <jfmlimcv@yahoo.it> wrote:

Thanks Peter, your help has resolved my problem.
Thanks again!
Fabio