How to place a picture at some user input specific pixels on the screen in android. if a user taps at a certain point than an image should be pasted on that point. my main concern is not getting the pixels but putting an image within that set of pixels (I am having a set of pixels within that i have to re-scale the image and than place it at that position )
as told by Ran hassid first find the touch coordinates on screen by using
view.setOnTouchListener(new View.OnTouchListener() {
#Override public boolean onTouch(View view, MotionEvent motionEvent) {
motionEvent.getX()
motionEvent.getY()
return false; } });
and then follow this answer to show image at obtained cordinates by above code-
link
Related
What I need is to be able to know which regions on a image is being pressed, I have a piece of image taken from google earth, and there are some buildings that are relevant, the way that i am using right now is to place images with low alpha so they are transparent and placing them on top of the buildings, and implementing onTouchListener on them, but the problem with this is that only works on certain android devices, for example on an Samsung galaxy 4 they are on wrong places.
I need to be able to detect this buildings that are being pressed regardless of the screen resolution.
Thanks.
You need to use the touch events on the image to detect where the press happens:
this.view.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event)
{
final int x = (int) event.getRawX();
final int y = (int) event.getRawY();
}
}
You will need to scale the X and Y coordinates by the size of the view to get the position touched within the original image.
How do I make the following type on Menu? I made it but the buttons dont touch the sides and
they leave out the background..
Help?
What I would suggest is that you make an ImageView and set the background image as the one you have shown. Then handle the onTouch event on it according to position of touch. So by trial and error get the bounds you want for all three regions. You can get the position of click using:
#Override
public boolean onTouch(View v, MotionEvent event) {
int x = event.getX();
int y = event.getY();
return true;
}
So use the x,y coordinates you get using this code and the bounds for the 3 parts of the image you get by trial and error. Compare them and accordingly execute your code.
Hope it helps! Cheers.
I am using the getX() and getY() functions in MotionEvent to get the x and y positions of where the user touched the screen. I am also capturing images using the android camera. These images are 480x640. My intention is to use have the user draw a box and the get the start and end x,y positions and use them to create a box and crop the image.
Unfortunately, even if the user boxes the correct area using the android screen (which shows video from the camera), the coordinates from MotionEvent do not relate at all to the correct location on the image. Sometimes the x,y coordinates I get from the MotionEvent are actually more than 480 or 640.
Are the dimensions of the android screen different than the image's? Or do the x,y positions from MotionEvent correspond to something else
The coordinates returned depend on the pointer being used but in general are in screen coordinates, so to get the coordinates relative from the view you need to offset by the views position.
See:
http://developer.android.com/reference/android/view/MotionEvent.html#AXIS_X
For offset of the view use:
https://developer.android.com/reference/android/view/View.html#getLeft()
https://developer.android.com/reference/android/view/View.html#getTop()
I'm trying to build a screen that shows a bunch of thumbnails at the bottom along with a full size version of the photos.
The thumbnails are (indirect) children of a HorizontalScrollView and the full size pictures are added as ImageViews of Fragments in a ViewPager.
What is the simplest way of zooming in on an ImageView? Zooming will use a fixed factor.
I've been unable to locate the Android Gallery source code, which might help me.
public boolean onDoubleTap(MotionEvent event) {
Log.e("test", "on double tap; event: "+ event);
Matrix m = new Matrix();
m.setScale(1.25f, 1.25f);
clickedImageView.setImageMatrix(m);
clickedImageView.invalidate();
clickedImageView.refreshDrawableState();
Log.e("test", "set image matrix after double tap event");
return true; // indicate event was handled
}
That code looks like it should work, just make sure you set
android:scaleType="matrix"
in the xml for the ImageView, or
clickedImageView.setScaleType(ImageView.ScaleType.MATRIX);
if you want to do it in the code. Otherwise the matrix you have set will not be applied.
Speaking of events we know that the touch screen method onTouchEvent (MotionEvent events) allows you to capture touch events on the screen and event.getX () and
event.getY () give me the coordinates of the touch as float values (ie values with a comma).
Specifically, I realized that taking logcat using the fixed point the finger in a mobile phone screen and not moving it, the event is not only perceived but MotionEvent.ACTION_DOWN MotionEvent.ACTION_MOVE and returned coordinates are manifold. This i can understand because the surface of the finger touches more points and more by reading the device coordinates believe that the finger moves while holding it.
My problem is that I would read the color of one pixel of a color image when I hold your finger still. In particular I need the central area occupied by the finger.
First, assuming you have a Bitmap object, I have to round to integer coordinates of the touch as the getPixel (intX, int y) coordinates of the entire Bitmap wants to return the pixel color.
Then how do I get the central point of touch? Be that there is a function that can help me? Keep in mind that while I stopped and read the value of a pixel on the image then I start to move slowly and even though I always record every move the center pixel. I need this because every move, if you change the color of the image in pixels, I want to vibrate or not the device.
If I could stop thinking about themselves in a dynamic array to store the coordinates of different pixels and search for the center of gravity, but moving I do not know what to do. I think however, that the research center of gravity, if not done very efficiently, can be slow during the move and then give the wrong results. If the CG is not quite enough for me to another point belonging to the environment.
I hope you can help me maybe with a few lines of code sketched.
Thanks in advance.
To get the touch position of finger, just cast the getX() and getY() to int and perform your desired tasks.
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN ) {
getPixelAt((int)event.getX(), (int)event.getY());
}
}
you can put you on main activity class when you can want to touch event occurs. let see you can put following code or not ? and return is most important as well.
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mDistanceX = 0;
}
return super.onTouchEvent(event);
}