Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS
Accepted Solution

Invert the colours of a graphic object?

Hello I am using the graphics object of an image to draw lines/rectangles etc..

 

How do I invert the colours in the graphics object?

 

Changing the blendMode to BlendMode.Invert affects the image (which there is none of) not the graphics object.

From,
Noah NU
Highlighted
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Invert the colours of a graphic object?

Can you set a ColorTransform( -1, -1, -1, 1, 255, 255, 255, 0 );

 

I probably won't get to test this until a little later, but I believe that should invert the image colors...

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invert the colours of a graphic object?

The colours were succesfully inverted.

 

Shouldn't applying the ColorTransform again change the colours back to how it was before or am I misunderstanding how the ColorTransform works?

From,
Noah NU
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Invert the colours of a graphic object?

[ Edited ]

 


noahnu wrote:

 

Shouldn't applying the ColorTransform again change the colours back to how it was before or am I misunderstanding how the ColorTransform works?


I believe so.  Are you seeing something different?

 

Also, I did get a chance to test it and it works for me ( from my original post ).

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invert the colours of a graphic object?

Thanks,

 

basically I made a toggle button by seeing whether it was inverted and setting or accordingly.

 

I used this function to see if the ColorTransform was inverted:

 

 

private function isInverted(ct:ColorTransform):Boolean{
			if(ct.redMultiplier == -1 && ct.greenMultiplier == -1 && ct.blueMultiplier == -1 && ct.alphaMultiplier == 1){
				if(ct.redOffset == 255 && ct.greenOffset == 255 && ct.blueOffset == 255 && ct.alphaOffset == 0){
					return true;
				}
			}
			return false;
		}

 

 

And this to set the value:

 

 

if(!isInverted(this.transform.colorTransform)){
					this.transform.colorTransform = new ColorTransform(-1,-1,-1,1,255,255,255,0);
					}
					else{
						this.transform.colorTransform = new ColorTransform(1,1,1,1,0,0,0,0);
					}
					break;

 

 

From,
Noah NU
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Invert the colours of a graphic object?

Transforms cause an effect for as long as they are applied to the object in question.  Remove them, and the original object is restored (because it was never changed, just filtered on-the-fly).


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Invert the colours of a graphic object?

[ Edited ]

 


noahnu wrote:

 

 ( slightly cleaned up the extra tabs )

if(!isInverted(this.transform.colorTransform)){
	this.transform.colorTransform = new ColorTransform(-1,-1,-1,1,255,255,255,0);
}else{
	this.transform.colorTransform = new ColorTransform(1,1,1,1,0,0,0,0);
}

 

 


You can always just set the removal like this:

 

if(!isInverted(this.transform.colorTransform)){
	this.transform.colorTransform = new ColorTransform(-1,-1,-1,1,255,255,255,0);
}else{
	this.transform.colorTransform = new ColorTransform();
}

The same results, though a little cleaner to read.

 

 

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invert the colours of a graphic object?

I know I already accepted the solution but:

 

Instead of filtering on-the-fly is there a way to actually apply it? I was thinking along these lines (as a workaround):

 

 

this.transform.colorTransform = new ColorTransform(-1,-1,-1,1,255,255,255,0);
this.graphics.lineStyle(1,0x000000);
var newBMP:Bitmap = new Bitmap(new BitmapData(this.width,this.height));
newBMP.bitmapData.draw(this);
this.graphics.beginBitmapFill(newBMP.bitmapData);
this.graphics.drawRect(0,0,newBMP.bitmapData.width,newBMP.bitmapData.height);
this.graphics.endFill();
this.transform.colorTransform = new ColorTransform();

 

 

this = Image

 

Basically I want it so that when a button is pressed everything gets inverted however any new things drawn to the image using the graphic object aren't inverted.

 

My code for some reason doesn't do what I intended.

From,
Noah NU
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Invert the colours of a graphic object?

You could always apply the colortransform, then use a bitmapdata object to draw the image. Then you can remove the image and replace it with a bitmap using the bitmapdata.

I am on my phone so I can't write out the code easily, but if you need me to expand I can when I get home.
--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invert the colours of a graphic object?

Isn't that what I did in the code I provided in my previous post?

From,
Noah NU