473,382 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 14525
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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.