I am using triangle shape button (PNG image), I need to make clickable only on the image visible area. As you can see in the image of my triangle shape button below , in the image I need to make clickable only on the image visible portion ie black and red, the green area will remain transparent and non clickable. Please help me this respect I would very thankful to you. Thanks in advance.
Identifying image area clicked in Android? check this question
OR if green will be transparent,
I think the easiest way to detect whether 'visible' content of the image was clicked, is to hook up an OnTouchListener, get the touch coordinates and subsequently get the color for those coordinates using Bitmap.getPixel(int x, int y). Since this will return an ARBG color, you should have little problems with images using an alpha channel. Anything that is 'transparent' (if green will be transparent?) will be invalid, everything else will mean the actual content was tapped.
something like this as a start up:
int color = Bitmap.getPixel(x,y); // x and y are the location of the touch event in Bitmap space
int alpha = Color.getAlpha(color);
boolean isTransparent = (alpha==0);
You can refer to this link:
Image Map
Or you can also refer this similar question :
Link
But, i would not recommend doing so as you have to manually calculate the coordinates and apart from that android screen has different sizes so it may cause a problem for you.
You can set OnTouchListener to your View and check was click inside of triangle shape or not (OnTouch event sends MotionEvent object, you can get coordinates of touch event from it).
May be it will be better, if button will be clickable as rectangle? Like here, on stackoverflow, vote buttons has triangle form too, but they are clickable on rectangle shape.
Related
I wonder is there a way to know the non-transparent area of a drawable image?
For example, I have this image:
What I want is to detect when people touch the transparent area it will do nothing and when people touch the non-transparent area (which is that start button) it will do something.
Thanks for you help.
Just check the pixel value of the touch position, if it is transparent do nothing.
how to get color at the spot(or pixel) of a image on touch event in android
Check if a pixel is transparent or NOT - Android
Seee the Image is nothing but the set of color pixel start fetching the pixels from the top left corner to the right and iterate till the bottom right, and maintain an array of only thos pixels into which event may trigger . Add checks while event generate and match the corresponding pixel's color code
I have this image:
And in Android I want to drag on the image and get the x and y. But only on the dark part (but a imageview/button is a rectangle). So a sort of round OnTouchListener.
How can I manage to do this?
You able to do it by Get touched pixel color of ImageView.
So, Step you need:
1. Get touched pixel color.
2. Compare touched pixel color with your image color . it is black.
So, you able to touched position in your desire image view position or not.
Thanks
suppose my bitmap is like
This image is actually in square transparent. I want to get the only viewable points as array so I can bound it and handle touch event on canvas. Right now it is square so when I touch at the corner of the image it still detect touch event on image. i don't want to do like this. Only if user clicked on viewable part then only action would be taken otherwise not.
For temporary I have used radius of image from center point it works fine but accurate, also if this image triangle part length is long then if it remain in square format user fill/get event on image outside.
I have used canvas to draw bitmap. Is there any other way or easy way to do this thing and handle event.
I have seen many games in that they used like custom shapes and touch event fire only on display part of object, how could i achieve this things.
Take a look at coordinates:
Android Canvas Coordinate System
and
http://code.google.com/p/apps-for-android/source/browse/trunk/SpriteMethodTest/src/com/android/spritemethodtest/CanvasSprite.java?r=150
Which goes into sprite:
http://p-xr.com/android-tutorial-how-to-paint-animate-loop-and-remove-a-sprite/
This may help too:
http://www.droidnova.com/playing-with-graphics-in-android-part-vi,209.html
Some of that should be helpful.
I want to crop my image which is being displayed on an ImageView. How I want to go about it is that I want a re-sizable rectangle to be displayed on the image. That rectangle will have moveable corners (which I can drag around with touch) to increase/decrease its size. The image below illustrates a demo of something I would like to develop.
P. S. I am not quite sure how to phrase my question.
What I want:
http://imageshack.us/photo/my-images/832/customcropbox.jpg/
The final solution I came up with after ample research was:
Extend ImageView to make my own custom view.
#Override onDraw method and do my custom drawing there in that method.
Implement onTouchListener on the view to get the touch events and process them according to their position.
e. g.
I checked whether the touch was in the radius of the anchor point circle I drew around the movable rectangle that I was drawing in my overriden onDraw method.
Edit:
I am sorry guys I don't have that piece of code anymore, I came here after a very long time otherwise would have loved to help you out.
Heartache.
I would like to be able to view a rather large image (floor plan) that can be fully viewed by moving around the picture. When I click on the image, I would also like to get the coordinates on that image.
I've followed this tutorial 1 which works correctly and so allows me to move around the image. After that I also added some functionality to get the position of where I touch the screen. However, when moving around the image, black borders surround it (see picture below), which causes me to get incorrect coordinates.
So would somebody know how I could a) fix/remove the black borders when moving the image or b) correct the coordinates I receive by e.g. removing the border offset?
1 http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-2-building-the-touch-example/1763
When you move around the image, set the scroll to stop before it reaches the edges of the image. Use this link for further details.
As for your coordinates, check these other 2 links: link1, link2.
Hope these would help you.