How to place toggle input points on an Image? - android

I am making an android application in which I want the user to tap on an image and a blob shows up and stores these points in the database. Very similar to the below image
from another app. Any ideas about what can be done? Is it overlaying on another picture or what?

you can identify the color from the image and check with color if you click on image that time specific color code pick and checked with predefine color, if match then you perform you operation.
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y); // x and y are coordinates
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
if(pixel == Color.RED){
// color is red
}

Related

How to change image backarrow color depending on the layout background image color?

Bitmap bitmap = ((BitmapDrawable)itemUserProfileBinding.ivItemUserProfile.getDrawable()).getBitmap();
// Bitmap imageProfile = BitmapFactory.decodeResource(activity.getResources(),arrayList.get(position).getProfile());
int pixel = bitmap.getPixel(20,20);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
int invertedRed = 255 - redValue;
int invertedGreen = 255 - greenValue;
int invertedBlue = 255 - blueValue;
itemUserProfileBinding.ivUserProfileBackArrow.setColorFilter(Color.argb(255, invertedRed, invertedGreen, invertedBlue));
In above code itemUserProfileBinding.ivItemUserProfile is my background imageView and itemUserProfileBinding.ivUserProfileBackArrow this is my custom toolbar back arrow imageView.
I have tried above but it is not working, can any one please help me.
Thanks in advance
I didn't properly understand your question but if you want to invert the complete bitmap then get each pixel in the image and then invert its RGB values.
If itemUserProfileBinding.ivUserProfileBackArrow is your imageview then I think you should first get the bitmap from the imageview and then invert the colours of that bitmap and then set the inverted bitmap to your imageview.
You can use Palette class to generate color and change it accordingly
//Gradle dependency
dependencies {
compile 'com.android.support:palette-v7:2x.x.x'
}
// Java
Palette.from(bitmap).generate(new PaletteAsyncListener() {
public void onGenerated(Palette p) {
// Use generated instance
// this is an Async call, You will get following colors in respect to bitmap
/*Vibrant
Vibrant Dark
Vibrant Light
Muted
Muted Dark
Muted Light*/
itemUserProfileBinding.ivUserProfileBackArrow.setColorFilter(p.getMuted(0x000000));
}
});

android: finding the position of a click within a button

I have a set of imageButtons placed within a relative layout, and each imageButton has a shape within it that is visible while the rest of it is set to alpha. I have currently set these buttons to slightly overlap, and I am trying to code it so that when the alpha part of one button is pressed, it ignores that button and checks the button underneath it.
I am currently using onTouch() with an OnTouchListener to get the x and y coordinates of the touch on the screen, but that is calculated based on the whole screen from what I can tell. Is there a way to use the position found from event.getX() and event.getY() to look at where the button is on the screen and see if that spot clicked on the button is transparent or not?
Use View.getLocationOnScreen() and/or getLocationInWindow().
https://stackoverflow.com/a/2226048/1979882
In order to check if alpha-channel exists, I would use:
public static Bitmap loadBitmapFromView(View v) {
Bitmap bitmap;
v.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
return bitmap;
}
and than detect the ARGB value to a particular pixel.
int pixel = bitmap.getPixel(x,y);
Now you can get each channel with:
int alphaValue = Color.alpha(pixel);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
https://stackoverflow.com/a/31775271/1979882

How can I give a color name against a hex color code?

I have a code that can only give hex code on touch pixel on image.
Now I want to give the name of the color as well.
How is this possible using Android?? Please suggest a way.
public boolean onTouch(View v, MotionEvent event) {
// get x coordinates
int x = (int) event.getX();
// get y coordinates
int y = (int) event.getY();
// get bitmap in touch listener
final Bitmap bitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
//xand y coordinates stored in to pixel
int pixel = bitmap.getPixel(x, y);
//RGB values
redValue = Color.red(pixel);
blueValue = Color.blue(pixel);
greenValue = Color.green(pixel);
selected_colour.setText(""+redValue+""+blueValue+""+greenValue);
selected_colour.setText("touched color:" + "#" + Integer.toHexString(redValue) + Integer.toHexString(greenValue) + Integer.toHexString(blueValue));
selected_colour.setTextColor(pixel);
return false;
}
});
What you're asking for is a bit tricky, because although there are many colours whose names are widely agreed upon (for instance, FFFFFF is called "White" everywhere), most other colour names are not a global convention but rather developed by the specific people who are naming the colours.
That being said, there are several tools out there which can do this. Check out this link, it's a website which you can provide a colour in hex code, and it will name it according to the closest pre-defined list of colour names.
You can view the javascript code and adapt it to Android. It's a pretty straight-forward algorithm which measures the distance of the colour you gave to the closest hit in a predefined colour list, by measuring the distance in RGB and HSL.

Color detection in a static image - OpenCV Android

I have an image with four squares red, green, blue and yellow. I need to get the rgb values of each squares. I'm able to get the rgb of the whole image, but i want it for a specific section.
The image which i am going to get will be from the camera and stored onto the SDCard
I don't know if I understand you exactly, but here it comes.
You need to create BufferedImage object to get RGB value:
File f = new File(yourFilePath);
BufferedImage img = ImageIO.read(f);
You can get RGB Color values from the image from then. You have 4 squares; to check their RGB values, you can check the corner pixels' RGB values:
Color leftTop = new Color(img.getRGB(0, 0));
Color rightTop = new Color(img.getRGB(img.getWidth - 1, 0));
Color leftBottom = new Color(img.getRGB(0, img.getHeight - 1));
Color rightBottom = new Color(img.getRGB(img.getWidth - 1, img.getHeight - 1));
After that it's easy to get red, green and blue values individually:
int red = leftTop.getRed();
int green = leftTop.getGreen();
int blue = leftTop.getBlue();
EDIT:
I'm really sorry, I didn't see it's for Android. As you said, Android doesn't have ImageIO class. To accomplish the task in Android, first initialize the image:
Bitmap img = BitmapFactory.decodeFile(yourFilePath);
From then the operation is pretty much the same:
int leftTop = img.getPixel(0, 0);
...
int red = Color.red(pixel);
int blue = Color.blue(pixel);
int green = Color.green(pixel);
Use this to crop your image.
Now to detect the color of the image take a pixel from the square and detect it's color with this.
After finding the RGB value use a simple conditional statement to see if the square is red blue or green.
I got it this way
int topLeftIndex = squareImage.getPixel(0, 0);
int R1 = (topLeftIndex >> 16) & 0xff;
int G1 = (topLeftIndex >> 8) & 0xff;
int B1 = topLeftIndex & 0xff;
and same way with
int bottomLeftIndex=squareImage.getPixel(0, picHeight - 1);
int topRightIndex=squareImage.getPixel(picWidth -1 , 0);
int bottomRightIndex=squareImage.getPixel(picWidth -1, picHieght - 1);

android Bitmap getPixel

I need to get the color of a pixel in order to compare it with a color from my color.xml file, but all values are negative and this comparison will always return a false result. How to get the proper color value? This color may be transparent. I've read this but I need an answer, not a link to theory.
bmp.getPixel(n.x, n.y) is returning zero when I'm expecting to return a propper value for color #00FFFFFF
Thanks
You could do something like this:
int pixel = Color.RED; //bmp.getPixel(n.x, n.y);
int a = Color.alpha(pixel);
int r = Color.red(pixel);
int g = Color.green(pixel);
int b = Color.blue(pixel);
String color = String.format("#%02X%02X%02X%02X", a, r, g, b); //#FFFF0000 for RED color
but instead of Color.RED you can put your bmp.getPixel(...) method.
Hope that helps
Best Regards

Categories

Resources