I would like to know how to mark a spot over an image.Marking would be on the touch of the screen would have an image to show that touch has been made over there.How can I achieve this, any example would be helpful.Thanks
In Activity override onTouchEvent method from which you can get the Event and from which you can get the complete information about the Touch (i.e., X, Y Cordinates, Pressure that user kept on the screen and even multiple Touch and many more).
Take the ImageView and override onDraw and draw the desired image at (X,Y) coordinates. Just use a small Loop to make it invisible continuously which looks like a haptic feedback.
Use the below code to make it transparent
ImageView myImage = (ImageView) findViewById(R.id.myImage);
myImage.setAlpha(127);
Thats it. You will get the desired effect if you properly worked on the above code.
Related
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've currently been thinking about how I could register only touch events on the visible (non-transparent) parts of a .PNG image.
-I've been testing around with AndEngine and it seems they have multiple options: I've tried any I could find to no avail.
-I could very possibly create my own method of checking a given touched area's transparency I suppose, but not sure how much work/overhead that might create with 15-20 objects on screen being able to be touched..
Any help is much appreciated!
One simple way to do it would be to grab the the pixel color at the touch location. Then you can check if the pixel is transparent:
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 trying to make a game. I try to use GridView but wonder how can I drag Item onTouchEvent(). I found an example
http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html
It is a great example. I cropped my image in 12 small image bitmap. display them on screen randomly on specific position.
By overriding the onTouchEvent() I got my requirement. Now I want to animate my image as the "swap" other image by animating. I have both images X,Y location.
I am wondring if it can by done by some Animation class.So that I should not put effort for doing it manually. I know it is not a hard job. But I Animation class can do it more smoothly.
So I have a ArrayOfImages(Bitmap) and I want to swap 2Images with animation. I am using a thread that update "Canvas" in background. Please help me.
.
I more thing. How can I add Scroll view with surface holder?? Is it possible? Because I think when I try to drag my image , It my not drag and active scrollbar for this response?
Finally I am using a loop for a specific x,y to a specific x,y while updating the canvas. Although this is not a efficient way.
I'm a bit stumped here, I'm trying to make it so an image (already in the drawable folder) gets created everytime you touch the screen and removed when the finger is lifted. I have the touch part coded already, overriding the onTouch method with a couple switch cases that handle each type of action (down, up, move, etc). But I can't for the life of me figure out how to make the image appear and then disappear with the coordinates (matrix?) of where the finger is.
Any help would be greatly appreciated!
You could use an object of the ImageView class to draw the image.
Get the co-ordinates of the touch event using the MotionEvent.getX(), MotionEvent.getY() or MotionEvent.getRawX(), MotionEvent.getRawY() functions (use the appropriate one depending on the kind of layout you are using, linear/relative). Use these co-ordinates as your ImageView object's left and top margins respectively.
Regrds,
Anirudh.