473,513 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BGR Color to Java Color

Took me a while to come up with this (even though it looks simple) it
will convert a BGR color int (or long) like used in VB to a java Color
(java.awt.Color)

examples of this are:
colornum = 16777215; //pure white
colornum = 255; //pure red
colornum = 65280; //pure green
colornum = 16711680; //pure blue

public Color BGRColorToJavaColor(int BGRColorNumber) {
//color codes as a ing in form "BGR"
return new Color((float)(BGRColorNumber & 0xFF),
(float)((BGRColorNumber >> 8) & 0xFF),
(float)((BGRColorNumber >> 16) & 0xFF));
}

Just putting this here to help people. my google groups search didn't
come up with anything like it, so i'm just trying to change that.

comments to my email please ;)

-Drew
Jul 17 '05 #1
5 14527
I don't understand the reason you convert to float.
You are doing bit operations that assume you have integers,
so why not use the "Color(int r, int g, int b)" constructor?

"Andrew Arace" <an**********@hotmail.com> wrote in message
news:11**************************@posting.google.c om...
Took me a while to come up with this (even though it looks simple) it
will convert a BGR color int (or long) like used in VB to a java Color
(java.awt.Color)

examples of this are:
colornum = 16777215; //pure white
colornum = 255; //pure red
colornum = 65280; //pure green
colornum = 16711680; //pure blue

public Color BGRColorToJavaColor(int BGRColorNumber) {
//color codes as a ing in form "BGR"
return new Color((float)(BGRColorNumber & 0xFF),
(float)((BGRColorNumber >> 8) & 0xFF),
(float)((BGRColorNumber >> 16) & 0xFF));
}

Just putting this here to help people. my google groups search didn't
come up with anything like it, so i'm just trying to change that.

comments to my email please ;)

-Drew

Jul 17 '05 #2
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
Took me a while to come up with this (even though it looks simple) it
will convert a BGR color int (or long) like used in VB to a java Color
(java.awt.Color)

examples of this are:
colornum = 16777215; //pure white
colornum = 255; //pure red
colornum = 65280; //pure green
colornum = 16711680; //pure blue

public Color BGRColorToJavaColor(int BGRColorNumber) {
//color codes as a ing in form "BGR"
return new Color((float)(BGRColorNumber & 0xFF),
(float)((BGRColorNumber >> 8) & 0xFF),
(float)((BGRColorNumber >> 16) & 0xFF));
}

Just putting this here to help people. my google groups search didn't
come up with anything like it, so i'm just trying to change that.

comments to my email please ;)

-Drew

SORRY SORRY, messed that post up: turns out my 'tests' i did were on
black, and it worked fine...need to get rid of that (float) casting

public Color BGRColorToJavaColor(int BGRColorNumber) {
//color codes as a int in form "BGR"
return new Color((BGRColorNumber & 0xFF),
((BGRColorNumber >> 8) & 0xFF),
((BGRColorNumber >> 16) & 0xFF));
}

That's right now. Really sorry about that, I felt like an idiot after
i posted it, and 5 seconds later realized I had posted the wrong code.

-Andrew
Jul 17 '05 #3
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
Took me a while to come up with this (even though it looks simple) it
will convert a BGR color int (or long) like used in VB to a java Color
(java.awt.Color)

examples of this are:
colornum = 16777215; //pure white
colornum = 255; //pure red
colornum = 65280; //pure green
colornum = 16711680; //pure blue


Isn't there already a Color constructor that does this?
Color red = new Color(255); // looks red to me
Color blue = new Color(16711680); // looks blue too
Jul 17 '05 #4
sg******@occ.cccd.edu (Stephen Gilbert) wrote in message news:<56*************************@posting.google.c om>...
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
Took me a while to come up with this (even though it looks simple) it
will convert a BGR color int (or long) like used in VB to a java Color
(java.awt.Color)

examples of this are:
colornum = 16777215; //pure white
colornum = 255; //pure red
colornum = 65280; //pure green
colornum = 16711680; //pure blue


Isn't there already a Color constructor that does this?
Color red = new Color(255); // looks red to me
Color blue = new Color(16711680); // looks blue too

hmm...i don't think so. i'll check out your examples there, but the
Color(int) constructor says "int rgb" where the color i am passing in,
the way VB represents it, its BGR (reversed endian)
....i hope i didn't spend that time for nothing.
Jul 17 '05 #5
an**********@hotmail.com (Andrew Arace) wrote in message news:<11**************************@posting.google. com>...
hmm...i don't think so. i'll check out your examples there, but the
Color(int) constructor says "int rgb" where the color i am passing in,
the way VB represents it, its BGR (reversed endian)
...i hope i didn't spend that time for nothing.


You're right. I wrote a test program and looked at it, but
forgot which part I'd made red and blue. The good news is
that your time wasn't wasted.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4195
by: Michael | last post by:
Hello I am trying to write a Java-Program which converts a XML-file in a HTML. It should take the Transformation-file from the XML-file itself. Below find a possible XML-file: <?xml...
0
6785
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
6900
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
0
2823
by: Markus Wollny | last post by:
Hello! When I try to run ./configure --with-java, it complains that ant doesn't work. However ant is installed, as is the latest Java SDK 1.4.2 from sun, PATH and JAVA_HOME are set correctly; ...
0
5640
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
5
2299
by: TZESENG | last post by:
DECEMBER 13, 2005 . Editions: N. America | Europe | Asia | Edition Preference News Analysis By Steve Hamm Source: http://www.businessweek.com/technology/content/dec2005/tc20051213_042973.htm...
12
5894
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
3251
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
5
6259
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.