Forum Topic: hexadecimal to retrive a colour

(148 views • 18 replies)

This topic is 1 page long.

<< < > >>
None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 11:39 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

I know that somehow using bitmap data or something that i can get the colour from a bitmap object. Thing is though i have never worked with these type of things. So i ask newgrounds two questions:

how do i get the colour of a object (colour squares) and store it as a variable to be called latter in the hexadecimal parameter for the drawing api

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 6/19/09 11:41 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,510

At 6/19/09 11:39 AM, Yambanshee wrote: how do i get the colour of a object (colour squares) and store it as a variable to be called latter in the hexadecimal parameter for the drawing api

You can use getPixel(x, y) or getPixel32(x,y) if you're using alpha to retrieve the color. Then just store it in a variable cast as uint

var color:uint = getPixel(20, 50);

All sites currently down. Deal with it. <3

BBS Signature

None

northxiv

Reply To Post Reply & Quote

Posted at: 6/19/09 11:46 AM

northxiv NEUTRAL LEVEL 02

Sign-Up: 06/18/09

Posts: 72

Also, one minor note is that if your image is being imported in to the library, the hex values will not be the same in Flash as they might be in Photoshop. Even when importing an image in, Flash will compress it somewhat, which will distort the actual color values. I figured this out when I was trying to generate an image with specific pixel values in Photoshop, yet when I traced the values in Flash, they were different.


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 11:53 AM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

thanx, but for some reason the code i use doesint work. i used:
trace(thing.getPixel(_root._xmouse, _root._ymouse));
but it always returns as undefined

thing is a screenshot that i turned into a movieclip and even selected the convert to bitmap at runtime option.

im using AS2 btw

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/19/09 12:00 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

Is the trace happening as soon as the flash is loaded? Put it inside onMouseDown and then click the image and it should work.


None

Johnny

Reply To Post Reply & Quote

Posted at: 6/19/09 12:03 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,510

Didn't realize you're using AS2.0. I don't think uint was supported. You can use :Number instead.

Like Liam said, also make sure the image is fully loaded before trying it.

All sites currently down. Deal with it. <3

BBS Signature

None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 12:05 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

its on a onEnterFrame loop

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/19/09 12:10 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

At 6/19/09 12:05 PM, Yambanshee wrote: its on a onEnterFrame loop

Strange, post your code :p


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 12:12 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

full code. I was playing around with this to learn it so i got nothing else on this fla but a bitmap movieclip

var myvar:Number = 0
function onEnterFrame() {
	myvar = thing.getPixel(_root._xmouse, _root._ymouse)
	trace(myvar);
}

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

UnknownFury

Reply To Post Reply & Quote

Posted at: 6/19/09 12:20 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

I'm fairly sure you can't do it like that. Try something along the lines of:

import flash.display.BitmapData;
import flash.geom.Matrix;

var bmp:BitmapData = new BitmapData(550, 400);

var m:Matrix = new Matrix();
m.tx = theMC._x;
m.ty = theMC._x;
bmp.draw(theMC, m);

trace(bmp.getPixel(50, 50));

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

Johnny

Reply To Post Reply & Quote

Posted at: 6/19/09 12:21 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,510

You might have to place that movieclip inside a bitmapData object in order to use the setPixel function properly.

Then reference the bitmapData object directly:

bitmapData.getPixel(x,y);

All sites currently down. Deal with it. <3

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/19/09 12:29 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

Aha, so the problem was you were trying to get the pixel of a bitmap object.. haha. Yeah, it has to be a bitmapdata object not an actual bitmap, so you need to draw the bitmap to the bitmapdata.


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 12:56 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

well it works, but i've got my next problem.
current code:

btn.onPress = function() {
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	var bmp:BitmapData = new BitmapData(600, 400);
	var m:Matrix = new Matrix();
	m.tx = btn._x;
	m.ty = btn._y;
	bmp.draw(btn, m);
	rgb = bmp.getPixel(_root._xmouse, _root._ymouse);
	rgb = "0x"+rgb;
	var obj = new Color("obj");
	obj.setRGB(rgb);
};

and the swf

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

knugen

Reply To Post Reply & Quote

Posted at: 6/19/09 01:10 PM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,685

At 6/19/09 12:56 PM, Yambanshee wrote: rgb = "0x"+rgb;

Try removing this line, it's not the correct way to convert a decimal number to hexadecimal, and you don't need to pass the setRGB function a hexadecimal value.


Elated

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 01:14 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

At 6/19/09 01:10 PM, knugen wrote:
At 6/19/09 12:56 PM, Yambanshee wrote: rgb = "0x"+rgb;
Try removing this line, it's not the correct way to convert a decimal number to hexadecimal, and you don't need to pass the setRGB function a hexadecimal value.

That sure did fix it :D

Thanx a lot to all of you! sorry for seeming to ask such noobie questions, but through my past experiance i have never worked with this!
I think that's all I'm gonna need, thanx guys!

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

knugen

Reply To Post Reply & Quote

Posted at: 6/19/09 01:30 PM

knugen LIGHT LEVEL 35

Sign-Up: 02/07/05

Posts: 4,685

By the way, if you would still like to do the converting (to show on screen or something), do this:

var rgbString:String = "#" + rgb.toString(16);

None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 01:43 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

At 6/19/09 01:30 PM, knugen wrote: By the way, if you would still like to do the converting (to show on screen or something), do this:

var rgbString:String = "#" + rgb.toString(16);

thanx, ill keep it in mind what i made with all your help!

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 6/19/09 02:06 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,541

Just for the record, Flash has a colour picker component .. lol :P


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 6/19/09 04:06 PM

Yambanshee DARK LEVEL 11

Sign-Up: 10/05/08

Posts: 1,587

At 6/19/09 02:06 PM, liaaaam wrote: Just for the record, Flash has a colour picker component .. lol :P

:O oh well. Dont know how to use them anyways + now i learned a new thing :D

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 08:41 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!