Custom java color creator? - java

There are only a few standard colors available in the API - Java.Color. I want many more colors.
I want to create my custom colors using some GUI color maker, then get the code for that and save it as a custom color which can be used later.
How can I do this ?

Have a look at JColorChooser. It enable users to choose from a palette of colors. Read more at How to Use Color Choosers.

Check out this applet i use it when i want to find a particular colour code for a custom colour
http://www.javaview.de/vgp/tutor/color/PaColorDemo.html
just take note of the RGB values and build the custom colour using these

Go to http://www.colorspire.com/rgb-color-wheel/ and select your color and in code create the color object with r, g, b values.

Related

Most efficient way to set TextView colour

What's the most efficient way to set the color of a TextView and why? Is there 1 method that is more memory and/or processor efficient? Or is there no difference at all to what happens with my app when it's running? Is it better to refer to a colour resource than declare RGB everytime I set a colour?
Option 1 (using RGB channel)
myTextView.setTextColor(Color.rgb(154,160,166))
Option 2 (using colour parser)
myTextView.setTextColor(Color.parseColor("#2B3A11"))
Option 3 (using colour resource from colors.xml)
myTextView.setTextColor(ContextCompat.getColor(context, R.color.<name_of_colour>))
Option 1 Should be the fastest way to set color to your TextView. With option 2 being a very closed Second. Because both RGB values and Hexcodes function in a similar way. It all comes down to the functions they are called from and how these functions are executed in the background (look rgb parseColor for these function's description and implementation ).
As
myTextView.setTextColor(...) is the same. So what happens to your textview in the background remains the same only the picking up of color is done differently.
Is it better to refer to a color resource than declare RGB everytime I set a color?
Ans- It depends on the your own usage,for example if you want to use a color multiple times and find it harder to remember the rgb code then you should definitely save the color int the color resource and refer to it later. The color resource was created for this purpose only right! And as #Fancesc mentioned it does make your documents readable and maintainable. Hence, the more professional way of doing things.
On the other hand using rgb right whenever needed saves you a lot of trouble.
You don't need to save any data anywhere.
While using you don't need to search the whole color resource file.
99% times the color model used is rgb/rgba, so everything you do ends up here.
Plus newer updates make it easier to work on rgb and hex values for colors. one such example is shown here.
Good for people who are bad with color names.
I am assuming you knew all of this already but decided to ask it anyways.XD. Have a good Day.

RGB color of pixel

I wanna make the same(https://play.google.com/store/apps/details?id=appinventor.ai_yuanryan_chen.BT_LED) app. I want to get a color of some pixel like here(https://i.stack.imgur.com/ixz84.png). How can I get the color(rgb)?
You don't need to do it from scratch since there is a set of readily-made libraries for colour picking, for example, this library:
https://github.com/jbruchanov/AndroidColorPicker
for more libraries you can check this:
https://android-arsenal.com/tag/18?sort=created

Need a way to get the Text in the Image in Black/white

I have a colored textual Image to be in black and white.
Specifically the text to be in black and background to be in white for whatever colored it might be
I am using JAVA to perform this operation.
Can anybody help me out to with a code snippet or point me to a discussion which is useful.
if you want to develop your own converter RGB to Black/White, please check Java - get pixel array from image . Here you import a image, access the pixel and with a specific threshold of the color you can decide to convert to black or white.
Or you use http://www.imagemagick.org/ as commandline tool (with api http://www.imagemagick.org/script/api.php).
Regards

Java: Taking a Image and turning it into Black in White with RGB

So I am doing a group project for my programming class, we are makeing a photo editing program and one of my parts of the program is taking the image and turning it into black and white using rgb. I was wondering what would be the best value or way in RGB to achieve black and white?
I would recommend letting the Java 2D library worry about the conversion:
create a greyscale BufferedImage (BufferedImage.TYPE_BYTE_GRAY);
get a graphics context by createGraphics()
ensure that colour rendering is accurate on that graphics context: call setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY)
draw the colour image you want to "convert" to the graphics context
If you do the conversion "manually" and you want to do it as accurately as possible, then you need to take into account that the eye is more sensitive to certain colour components than others. (If you want a "rough and ready" conversion, you can average the colour components, but this isn't strictly speaking the most accurate conversion.)
For each pixel, you can convert the RGB to HSB (using Color.RGBtoHSB), set the saturation to 0, and convert back to a Color instance using Color.getHSBColor.
Wikipedia actually has a good piece about how to perform the transformation once you have the RGB colors.
Hey , this page has many Java Image filters which are freely available for download.All filters are standard Java BufferedImageOps and can be plugged directly into existing programs.The GrayscaleFilter can convert the image to black and white
Using java.awt.image.ColorConvertOp with a gray destination ColorSpace is very efficient. There's an excellent example here.

java color image processing

I am trying to get the different amount of colors inside an image in java, but I don't know if there is a library for this propose of not. the project is about finding out the different colors from one image, and then print out the name of the colors. any idea??? please help me if you have any answer.
You can turn an image into a BufferedImage and call getRGB(int x, int y) to get the rgb for each pixel. Then you can use one of the many color websites such as this one or this one to map the rgb to a color name. Just find the named color which is the closest in distance to each rgb in the image.
Java has the Java Advanced Imaging (JAI) library which is built to allow stuff like this.

Categories