I'm trying to create a color picker for Android that looks like a minimalistic version of Gimp's. So, it has a hue slider and a rectangle with saturation/value variants of a color chosen in hue slider.
Question: what is the best way to create the rectangle?
Right now, I'm creating an 200x200 array of pixels, but it takes ~5sec to create and display rectangle with that array. And I need colors in rectangle to change whenever I change the value in hue slider...
Rectangle is bitmap, btw. Can I use color matrices on that and how? Any examples?
Thanks in advance!
You can create the rectangle with saturation/value variants that change according to the selected hue, by drawing the rectangle with LinearGradients.
You can incorporate the code here: http://code.google.com/p/android-color-picker/ into your application. Seems that this is what you want.
OpenIntents has a very nice color picker you can use. It can be installed as an independent app and launched with Intents.
Code: http://code.google.com/p/openintents/source/browse/#svn/trunk/ColorPicker
Screenshots/download: http://www.openintents.org/en/colorpicker
Intent specification: http://www.openintents.org/en/node/670
One possibility is to pre-create the rectangles on your developer PC for each slider position, embed them as resources, and then swap in the right one when the slider changes. This may make for a portly application, but it will be nice and quick.
I have not dealt with the 2D graphics API much, so I don't know if there are other possibilities (e.g., color matrices).
Can this be applied to an image color picker as well?
Use case:
Select a particular pixel on an image.
The pixel selected generates a color on a rectangle shape.
Perhaps generating color codes for the pixel selected?
Related
have a good day, i want to know if there is a css code which change the circle shape color to black and white linear color, like the following image
https://i.stack.imgur.com/7YGia.jpg
you need to use "linear-gradient" for example:
-fx-fill:linear-gradient(to bottom, #FFFFFF, #000000);
see the Javafx Css Reference Guid
I want to create a clickable image, my image has some different clickable parts in it, like this one:
I want to draw a custom shape like :
A,B,C,D,E,F
and make sure when user click on of this something happen.
the problem is I don't have any kind of idea to, how create shapes like the shapes in the image make sure it just fix on the image and in different screen size don't see a massed up thing.
Will there be more than many of such images?
If no I suggest you to create mask image for each region where black part of image represents the region and white part excludes rest.
To draw image:
create custom View
in constructor don't forget to use setWillNotDraw to true so you can do custom drawing
override View.onDraw method where you can draw main image and all others with some filters via setColorFilter.
To handle click events:
override onTouchEvent method
get touch position
compare touch position with point color in mask image
To optimise:
create mask image downscaled by some scale factor
during comparison divide touch position by scale factor
This is not ideal, but solution with vectors is non trivial I think
Take it as image and setOnclickListner for that image
I am making a 2D Java game and I'd like to darken stuff in the dark areas. I was wondering if I could use alphatransparent colors in a paintComponent method. If not, does translucent PNGs work or is there effects for darkening images.
Thanks
I would create a new BufferedImage of type TYPE_INT_ARGB, edit straight into the raster data, - set the color of your choice (with desired alpha), and just draw it after everything else, in your paint method. drawImage is pretty fast. And if you want to change the darkness colors, you can set the new alpha values on the fly directly into the data array of the image.
You can use transparency/opacity in java.
Here you can find some basic info on the procedure. The important step is using an AlphaComposite object to set the alpha value of your drawing
I need to create different image size with green color in microedition, is it possible?
I need to create the image on the fly without loading an image.
Here you go,
http://www.java2s.com/Code/Java/2D-Graphics-GUI/DrawanImageandsavetopng.htm
change the color from black to green in example.
If you want images to be unique draw unique numbers instead of text.
if you don't want to use text in the image then simply draw something but start the drawing at a random location in the image.
Out of curiosity are you trying to test the servlet or the phone app?
Sorry earlier I missed that you wanted to achieve this in J2ME
See the link below
http://www.java2s.com/Code/Java/J2ME/MutableImageExample.htm
I need to make a game in Java for a project.
What I'm trying to do is a game where you have to go through a maze without touching the walls.
Is there a way to get the color of the pixel the mouse is over?
You probably want java.awt.Robot.getPixelColor(x, y). It'll be faster than grabbing an image.
This post answers your question precisely including a complete working code example. Basically, you can create an image from canvas on which you draw and call getRGB() on a pixel on the image.
You want to implement the MouseMotionListener interface and do what Artelius mentioned, namely, get the coordinates of the mouse position and calculate the color of the pixel.