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
Related
is there any way to blur only part of an image in android?
searched a lot but dint find any help.
most of the examples use gaussian blur which blurs full imageview.
i want to allow user to dynamically draw rectangle on imageview & on action up
area within rectangle should be blured.
any help will be really appreciated.
Bluring images on the fly is not an easy task, ask Roman Nurik (The one behind Muzei app)
He gave useful tips on this Google+ post but it's for animated images, from focus to blur.
In your case, I would say that you need to (roughly):
Get the bounds of the drawn rectangle
Get the image part that corresponds to the previous bounds
Blur on the fly the previous image part
Draw, into the same canvas, the blurred image part on top of the original image
Set up a onDrag Listener to move the drawn rectangle and do again step 1
EDIT: After re-thinking about it, computing and draw a blurred area each time the drawn rectangle move it too heavy, it won't work. The solution is probably this:
Blur the entire image and keep it into memory
Get the bounds of the drawn rectangle
Get the part of the blurred image that corresponds to the previous bounds
Draw, into the same canvas, the blurred image part on top of the original image
Set up a onDrag Listener to move the drawn rectangle to do again step 2-3-4
put the image view in a relative layout.
you detect the touch events of the user.
for each rectangle that he is drawing, you add an image view of it is size superposed to the initial one (I mean in the same relative layout) and of course with your blur effect.
you will see your image view blured part by part ...
put another layout on the half part of the image and set a translucent type background to the layout.
Once you have drawn your rectangle set alpha = 0.5 or as per your need so that your dynamic view that you have drawn will look blurred.
This is code for blur:
http://shaikhhamadali.blogspot.in/2013/07/gaussian-blur-imagebitmap-in-imageview.html
In this code computeConvolution3x3 method is used for computing the blur.For computing blur it convert the bitmap in to pixel array then it apply on those pixel. So you have to just do is get pixels array of that part of the image that you want blur.
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
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.
I have a dial-or image as shown in which whenever i move the finger in clockwise manner the part covered of sub ring gets yellow in color.I tried to apply this scenario through gesture overlay but do not serve the requirement.
Any idea is welcomed.Please assist me and thanks in advance.
I'm working on a small app that uses sprites which are rendered using a canvas and simple drawBitmap.
Once the user touch the screen I need to know which sprite was clicked on.
I'm able to achieve this goal when I treat each sprite as a rectangular which has the width and height of the image.
However, some of the sprites takes only small portion of the entire rectangular and I would like to ignore when user clicked inside the rectangular but not on the internal shape.
Any ideas what could be a good method to do that?
Edit: Just to be more clear, lets say I have a sprite with size of 200x200, the sprite is an image of an airplane from above and the airplane has long long wings. Since the wings are long there will lots of "dead" areas in the sprite.
I would like to detect when user clicks the airplane itself only and not the "dead" area.
Thanks.
You will need to create a 2d array of all the pixels in the bitmap. Mask the pixels to either a 0(transparent) or a 1(has color). Then when you click inside of a rectangle you will just need to get the width offset and the height offset within the rectangle. This gives you your indices for mapping to the pixel array. Then check and see if the index in the pixel array contains a 1 for a value. If so then you clicked on the actual image. Does that make sense?
You have to check for the area where your Bitmap gets drawn, not another rectangular shape. Just treat every sprite (which may have different sizes) as a single rectangle, whose width and height equals to the width and height of the sprites.
Since you elaborated your question I'll give another suggestion.
When you have detected a click on the sprite, simply check (in the Bitmap's area) the current pixel via the Bitmap.getPixel() function. You can then easily check if the color at the specified position is something you're interested in, otherwise you can just skip detecting the touch.