From: Tommy W on
Hi,
I have a wxImage which I want to make see-through.
What would be the best way of achieving this?

char alpha[WIDTH* HEIGHT]; /* set the values here */
or should it be
char alpha[WIDTH*HEIGHT*3]; !?

wxImage i(_T("file.png"));
i->SetAlpha(alpha,true);
wxBitmap *b = new wxBitmap(i);

Is this the proper way to do it ?

performing a
for(int y;y<height;y++)
for(int x;x<width;x++)
i->SetAlpha(x,y,value);

seems abit slow.
And how 'slow' is wxBitmap *b = new wxBitmap(i);
I guess it would be stupid to do it in the PaintEvent ?

Thanks in advance
/Tommy Wallberg

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Vadim Zeitlin on
On Fri, 20 Apr 2007 19:48:40 +0200 Tommy W <tommy(a)svearike.sytes.net> wrote:

TW> I have a wxImage which I want to make see-through.
TW> What would be the best way of achieving this?

If you want just on-or-off transparency, then you can use a mask, i.e.
select one of the image colours to be transparent. Otherwise you should use
alpha.

TW> char alpha[WIDTH* HEIGHT]; /* set the values here */
TW> or should it be
TW> char alpha[WIDTH*HEIGHT*3]; !?

No, alpha is 1 byte per pixel, just as the colour channels.

TW> wxImage i(_T("file.png"));
TW> i->SetAlpha(alpha,true);
TW> wxBitmap *b = new wxBitmap(i);
TW>
TW> Is this the proper way to do it ?

You don't need to do anything if you load wxImage from a PNG with alpha.
If you do set alpha data yourself, you need to at least initialize it.

TW> And how 'slow' is wxBitmap *b = new wxBitmap(i);

Quite slow. BTW, you really don't want to create bitmaps on heap as
they're already pointers internally. Just do "wxBitmap b(i)".

TW> I guess it would be stupid to do it in the PaintEvent ?

Yes, avoid if you can. If you can't, look at wxRawBitmap.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org

From: Tommy W on
On Saturday 21 April 2007 13:15, Vadim Zeitlin wrote:
> On Fri, 20 Apr 2007 19:48:40 +0200 Tommy W <tommy(a)svearike.sytes.net>
> wrote:
>
> TW> I have a wxImage which I want to make see-through.
> TW> What would be the best way of achieving this?
>
> If you want just on-or-off transparency, then you can use a mask, i.e.
> select one of the image colours to be transparent. Otherwise you should use
> alpha.

The effect I'm looking for is "grayed-out", if you understand what I'm
meaning?

> TW> char alpha[WIDTH* HEIGHT]; /* set the values here */
> TW> or should it be
> TW> char alpha[WIDTH*HEIGHT*3]; !?
>
> No, alpha is 1 byte per pixel, just as the colour channels.

It was just that the documentation was a bit unclear,
thanks for the elaboration.

> TW> wxImage i(_T("file.png"));
> TW> i->SetAlpha(alpha,true);
> TW> wxBitmap *b = new wxBitmap(i);
> TW>
> TW> Is this the proper way to do it ?
>
> You don't need to do anything if you load wxImage from a PNG with alpha.
> If you do set alpha data yourself, you need to at least initialize it.
>
> TW> And how 'slow' is wxBitmap *b = new wxBitmap(i);
>
> Quite slow. BTW, you really don't want to create bitmaps on heap as
> they're already pointers internally. Just do "wxBitmap b(i)".
> TW> I guess it would be stupid to do it in the PaintEvent ?
>
> Yes, avoid if you can. If you can't, look at wxRawBitmap.

I will look that one up,
thanks for all your help
/Tommy

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org
For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org