Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » How must Alpha be managed ??
How must Alpha be managed ?? [message #38508] Fri, 21 December 2012 00:16 Go to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi all,

I am currently trying to draw buttons that are transparent but they have special shapes.

For rectangles: it is easy, all I have to do is draw a small img in iml designer, set the RGBA values for all points and then use this image to draw in the dest rectangle.

For other shapes (circles for ex), I try to use ImageDraw and Alpha() method and it works ...

Question:
In the iml designer: all points are set to : RGBA(46,46,46,51)
Using Image Draw, I draw a circle with Color(46,46,46) and apply GreyColor(51)
... expecting to get RGBA(46,46,46,51)
But the result is not the same at all !! Sad

Which is the way to go ?? (the color obtained with src image gives me the result expected by client )
Re: How must Alpha be managed ?? [message #38512 is a reply to message #38508] Fri, 21 December 2012 09:49 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Didier wrote on Fri, 21 December 2012 00:16

Hi all,
For other shapes (circles for ex), I try to use ImageDraw and Alpha() method and it works ...



Hello Didier,

if possible I would like to see an example with button having a non standard shape. That of circle would be fine.

Thanks,
Luigi
Re: How must Alpha be managed ?? [message #38513 is a reply to message #38512] Fri, 21 December 2012 10:31 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hi,

take a look at this reference example:

Chameleon


Regards,
omari


regards
omari.
Re: How must Alpha be managed ?? [message #38520 is a reply to message #38513] Fri, 21 December 2012 14:47 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Thankyou for you're replies

Quote:

Hi,
take a look at this reference example:
Chameleon
Regards,
omari


I started from this example to manage drawing my own shapse but the problem is about Alpha management which is not explained in the reference example.

I think Premultiply() function must be used but how and when ???

Quote:

Hello Didier,

if possible I would like to see an example with button having a non standard shape. That of circle would be fine.

Thanks,
Luigi


I will upload an example in 30 min with a sample shape I'm working on where we see two different ways to draw the shapes and the problem I encounter with tranparency
Re: How must Alpha be managed ?? [message #38524 is a reply to message #38520] Fri, 21 December 2012 16:24 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Luigi,

Here is the example promised.

As for my problem:

Buttons 'CASE 1', 2 and 3 are the same but 'PREV' button doesn't have the same transparency.

On the other side, buttons 'CASE 4', 5, 6 and 'NEXT' have the same transparency.

Doing the example showed me that this has to do with the color used to fill the ImageDraw after applying the alpha value

... Still searching
Re: How must Alpha be managed ?? [message #38533 is a reply to message #38524] Fri, 21 December 2012 21:53 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hi,

to draw a transparent rectangle, you can draw lines:

void DrawRect(Draw&draw, Rect& r, int w = 1, Color c = Black())
{
	Vector<Point> ps;
	ps << r.TopLeft() << r.TopRight() <<
	r.BottomRight() << r.BottomLeft() << r.TopLeft();
	
        draw.DrawPolyline(ps , w, c);
}



to draw a transparent ellipse :

void DrawEllipse(Draw& w, Rect& r, Color c = Black(), int with = 1)
{
	Color nullcolor;
        nullcolor.SetNull();
        w.DrawEllipse(r, nullcolor, with, c);
}




Regards
omari


regards
omari.
Re: How must Alpha be managed ?? [message #38534 is a reply to message #38533] Fri, 21 December 2012 22:31 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Omari,

I'm not trying to draw empty rectangles or ellipstes.

What I'm trying to do is manage the Alpha value which gives the information about "how transparent it is" or "how opaque it is".

This I can do without any problem but I don't know what to put in alphaColor and alphaValue values :
ImageDraw iw(rect.Width(), rect.Height());
iw.Alpha().DrawRect(bandRect, GrayColor(e.alphaValue));
iw.Alpha().DrawEllipse(circleRect, GrayColor(e.alphaValue));
w.DrawImage( rect, iw , e.alphaColor);

in order to get the same result as if id did:
w.DrawImage(bandRect, e.bandStyle );

where bandStyle is an image containing RGBA pixels where ALPHA is not 255 nor 0

Look at the example I uploaded

[Updated on: Fri, 21 December 2012 22:32]

Report message to a moderator

Re: How must Alpha be managed ?? [message #38550 is a reply to message #38508] Sun, 23 December 2012 10:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Thu, 20 December 2012 18:16

Hi all,

I am currently trying to draw buttons that are transparent but they have special shapes.

For rectangles: it is easy, all I have to do is draw a small img in iml designer, set the RGBA values for all points and then use this image to draw in the dest rectangle.

For other shapes (circles for ex), I try to use ImageDraw and Alpha() method and it works ...

Question:
In the iml designer: all points are set to : RGBA(46,46,46,51)
Using Image Draw, I draw a circle with Color(46,46,46) and apply GreyColor(51)
... expecting to get RGBA(46,46,46,51)
But the result is not the same at all !! Sad

Which is the way to go ?? (the color obtained with src image gives me the result expected by client )



Actually, you are doing the right. In fact, ImageDraw uses R channel as alpha.

Anyway, I think the difference you can see MIGHT be because of alpha channel premultiply issue. E.g. RGBA(46, 46, 46, 51) can never be present in Image (it is invalid value). If you have applied 51 alpha to RGB(46, 46, 46), you should get something like RGBA(46, 46, 46, 9) if you read pixel from Image created from ImageDraw.

Mirek
Re: How must Alpha be managed ?? [message #38555 is a reply to message #38550] Sun, 23 December 2012 13:10 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Quote:

RGBA(46, 46, 46, 51) can never be present in Image (it is invalid value).

I don't understand why it is invalid value since this value can be reached with iml designer ?

Anyway this issue does not block the development so I'll keep searching
Re: How must Alpha be managed ?? [message #38556 is a reply to message #38555] Sun, 23 December 2012 13:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Sun, 23 December 2012 07:10

Quote:

RGBA(46, 46, 46, 51) can never be present in Image (it is invalid value).

I don't understand why it is invalid value since this value can be reached with iml designer ?



Ops, sorry, my premultiplied alpha info got rusted, in fact above RGBA is valid (but RGBA(51, 51, 51, 46) is not).

Anyway, I still think that this is the issue you are experiencing. And iml designer displays RGBA in "straight" unmultiplied form, which might be the source of confusion.

Mirek
Re: How must Alpha be managed ?? [message #38560 is a reply to message #38556] Sun, 23 December 2012 21:20 Go to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
iml designer displays RGBA in "straight" unmultiplied

Ahhh, This is the info that was missing Smile

I think I'll be able to manage from now

Thank's for helping me

[Updated on: Sun, 23 December 2012 21:20]

Report message to a moderator

Previous Topic: Clipping region
Next Topic: Painter and transformations
Goto Forum:
  


Current Time: Fri Apr 19 16:02:37 CEST 2024

Total time taken to generate the page: 0.03412 seconds