I want to know if there is a way to check if the user touched the bitmap, ofcourse im talking about an image without background, like a circle, a triangle and so on.
Thanks!
image without background, like a circle, a triangle and so on
then you should probably override View's onTouch, retrieve x and y from the touch event you got as parameter and compare it with the coords of the shape you drawn. The easiest way is to use Rect.contains(int x, int y)
Related
In the android canvas, I have 5 shapes. In my case, I need to select one of them and move to new position. The same time need to find which one select by touch.
If You have drawn shapes by x, y coordinate and by width height then implement OnTouchListener interface and take touch of whole screen. Take touch coordinate x and y and match on onTouch implement method in which shape coordinate are touched.
I have an ImageView panning by Matrix using
m.postTranslate(x, y);
command.
I found that I can get the touched x, y position based on ImageView coordinate
by using inverse() method.
But I cannot find that I can draw a point on the ImageView based on its coordinate.
Simply, I want to create a point of interest and save the position on a map (ImageView),
and draw them together preserving the position of the point.
Please see also the image below that describes what I want to do.
http://img197.imageshack.us/img197/3214/qwms.png
If anyone can give me some clue, I will be very appreciated.
Thank you.
you need use a custom view for use the override metod onDraw()..thats u need for draw
I have a activity where I have two imageViews. In onTouch I recognize which imageView was clicked. Now I have a question. How I can draw new very small image in place where I clicked. I know that onTouch i have getX() and getY() and I save this position when I touch the screen, but I don't know how I can draw image in place where I clicked. My image is in drawable resources. I need to use canvas or is better way. I need draw this picture and after that I need run animation this image.
edit1: How can I set positionX and positionY my image. I have position where I click but I don't know how I can set image in this coordinates.
you should have a image view with visible attribute of FALSE and after touch (or any event you want) set three attribute : visible = true; x = getX() and y = getY();
is it enough or explain more?
I see the following approach.
Replace the ImageView by a custom view derived from ImageView.
Override onDraw.
call super.onDraw to draw the image
paint your image using onDraw's canvas at the last touch position.
each time you get a touch, you need to invalidate the custom view
I have a png, when I save it it is a square image, but inside the square png is a circle (sometimes its other shapes). How can I check when the user is over what is inside the png and a graphic rather than when a user is inside a png but is over transparency?
Yea, you can do this, you just need to manually check the color of the pixel where the touch occurred.
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);
Note: Depending on how you implement your touch listener will might need to convert the x,y location of the touch event to the x,y coordinates of the image view.
i am having an image in canvas.i want to get color at particular pixels and replace with user defined color.is it possible to do for abitmap placed in android canvas?
Thanks in advance..
Unfortunately Canvas is more like a write-only object: you can draw on the Bitmap, but you can't really get almost any information on the Bitmap. But if you have access to the Bitmap itself, this is a very easy task: just use Bitmap.getPixel(int x, int y) to get the color of the pixels and then draw whatever you need on the Canvas or even just call Bitmap.setPixel(int x, int y, int color) without creating any Canvas at all.
Sure. just bitmap.getPixel(x, y) and setPixel(x, y, color). Make sure that the bitmap your working on is mutable.
Image in Canvas with touch events