Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I am trying to make a 2d online game.
I want to start somewhere, so consider we have two devices A and B of different screen sizes, now when user1 touches somewhere on the screen of device A, I want to let user2 on device B to know exaclty where user1 touched.
For the MVC-View class of Displaya World coordinates will be converted to a physical coordinates of device's display called Viewport. Learn more. Android how to send touch event coordinates to another screen of different size and denisty and keep it? Ask Question. Asked 2 days ago. Active 2 days ago. Viewed 37 times. So I will explain this as simple as possible: I am trying to make a 2d online game.
SomeUser SomeUser 51 5 5 bronze badges. Active Oldest Votes. Thus you can hold World coordinates separated from physical ones of different devices.
Subscribe to RSS
There are many resources about Window to Viewport coordinate transformation on the Internet. I don't get what you mean, can you please see my update of my question, thanks.
SomeUser Please refer some Internet resources for further information. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.The reason for this tutorial is to make you more aware and at ease with the Android Canvas. It can happen that the requirements are so specific that you need to implement it from scratch.
Canvas plays a vital role in building such Custom Views. A Canvas is a 2D drawing framework that provides us with methods to draw on the underlying Bitmap. A Bitmap acts as the surface over which the canvas is placed. The Paint class is used to provide colors and styles. The invalidate method is used to redraw the view. It calls the onDraw method again. Typically, this is used when the text or color or view needs to be updated based on certain events.
The Canvas class contains methods to draw certain shapes just as line, arc, circle, over. Moreover, we can draw complex geometry too using Paths. In the canvas 0,0 is the top left point. As you move horizontally right the x coordinate increases. As you move vertically down the y coordinate increases in pixels.
Rect object is used to create a rectangle in which each side is specified in integer value.
RectF does the same but in float values. Inside the drawCircle method, the first two parameters passed are the coordinates of the center of the circle. The third parameter sets the radius for the circle. The last parameter sets the clipping region style. Inside the drawText method the two float values set the origin position of the text.
Elements are arranged on top of each other in the order in which they are drawn. Similar to a frame layout based on the z-order. Can you help me with this.? Activity getContext. Your email address will not be published. I would love to connect with you personally. Table of Contents 1 Android Canvas 1. Since canvas is drawn on the screen, views that are drawn need to be measured in terms of pixels px. Android Canvas Example Project.
Android Canvas Coordinate System. Why is Anti Alias flag needed in Paint? An Anti alias flag ensures that the shape is smooth. Android Canvas Basics Output 1. Android Canvas Basics Output 2. Github Project Link.This tip is about camera related coordinate system in android. When i develop camera related apps, inside onPreviewFrame i need to do image processing on byte data and show results on top of the canvas and i use OpenCV for the image processing in jni.
Android Coordinates: Camera, OpenCV in JNI, Canvas
So the whole workflows is from byte in android camera to cv::Mat in jni OpenCV and after image processing from cv::Mat to android canvas and draw results.
There are two things which affects the transformation, camera index and phone orientationlet's say using front1back0 to denote camera indexand using orientCase to denote phone orientationorientCase equals to 0,1,2,3 corresponds to.
Then L,T should multiple scaleW and scaleH before draw on canvas. From android camera to OpenCV in JNI: as shown above, the raw android camera image byte array passed to jni is usually not what we thought it should be, so we need to do some tweaking so that OpenCV sees what we thought it should see.
I use the following snippet to do this:. Don't forget to do sm. Things to note: canvas coordinate system is always fixed android camera coordinate system only depends on camera index when using front camera, imaging you are another person who is using your phone to point at you in other words the other person is using the back camera to look at youthat explains how camera coordinate system differs when camera changed in the above figure when plot on canvas, also need to take status bar height, menu bar height, and maybe some other component's height into considerations, the L,T coordinates shown above can not be directly used unless the image is exactly the same size of canvas no menu bar etc.
I am working with Canvas. The code that I already have is:. The problem is that, since Canvas. Any suggestion? Indeed, I am not even interested in drawing the Arc. I am just looking for a way to actually get those coordinates.
Maybe there is a way to create a curve within 3 points in java where I could get the coordinates. I would not mind using this method. I have already tried to follow this answer but the values that I get are not the correct ones. I have also checked Path from Android, but I not aware if it is possible to use it.
It seems that couple of methods arcTo and addArc could help, but I do not know how to attach it to the canvas, so I guess it is not possible to combine them. After finding another previous answerI have tried to implement it but the coordinates are again, wrong not even close to my endPoint.
Try the following using Path and PathMeasure. This sample class draws on a custom view. The arc is drawn then twenty small circles are placed along the arc. You can divide the path into as many points as you like by dividing the path length.
The array arcPoints will contain the selected points along the path. If you don't want to draw the arc or the points, just delete the code that does the actual canvas drawing.
The path will still be created and the points along the path captured. Learn more. Get coordinates from a drawn arc in a canvas Ask Question. Asked 1 month ago. Active 1 month ago. Viewed times.When dealing with locations in PDFViewCtrl it is important to understand what coordinate space they are located in.
For example when you get x, y value from MotionEventthe location is relative to the screen, not PDF page. PDF document has its own coordinate system, which differs from Android's view coordinate system. To illustrate this, here is a screen capture of an annotation and a table of its coordinates as PDF page coordinates, screen coordinates, and scrolling coordinates :.
The x axis extends horizontally to the right and y axis extends vertically upward. A page point represents a point in page coordinates. A PDF page may have a rotation associated with it. In this case, the coordinate 0, 0 may no longer correspond to the bottom left corner of the page.
For example, here is the same page shown as above, but rotated 90 degrees clockwise. Notice how the coordinate 0, 0 is now at the top left corner of the viewport. Point 0, 0 is at the top left corner of the view. The x axis extends horizontally to the right and the y axis extends vertically downward.
A screen point represents a point in screen coordinates. Since screen coordinates measure Android views, if PDFViewCtrl zooms in, the annotation's screen coordinates may change. For example, here are two screen captures of the same annotation before and after zooming in, and a table showing how its screen coordinates change:.
In scrolling coordinates, the point 0, 0 is located at the top left corner of the view in page 1. Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow. Select a platform to get started with your free trial. Some test text! Contact Sales. All platforms, one API Web. Integrations Salesforce. Resources Subscription. PDFTron for Android close. Free Trial Support.
To illustrate this, here is a screen capture of an annotation and a table of its coordinates as PDF page coordinates, screen coordinates, and scrolling coordinates : Coordinates x1 y1 x2 y2 PDF page coordinates For example, here are two screen captures of the same annotation before and after zooming in, and a table showing how its screen coordinates change: left x1 bottom y1 right x2 top y2 Before zoom in Integrate via NPM.
Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm trying to find information on how to change the coordinate system for the canvas.
I have some vector data I'd like to draw to a canvas using things like circles and lines, but the data's coordinate system doesn't match the canvas coordinate system. If I have to do my own calculations prior to each drawing call, how to I find the width and height of my ImageView?
The getWidth and getHeight calls I tried seem to be returning the entire canvas size and not the size of the ImageView which isn't helpful.
I tried to use the "public void scale float sx, float sy ", but that works more like a pixel level zoom rather than a vector scale function by expanding each pixel. This means if the dimensions are increased to fit the screen, the line thickness is also increased.
After some research I'm starting to think there's no way to change coordinate systems to something else. I'll need to map all my coordinates to the screen's pixel coordinates and do so by modifying each vector.
The getWidth and getHeight seem to be working better for me now. I can say what was wrong, but I suspect I can't use these methods inside the constructor.
Android Coordinates: Camera, OpenCV in JNI, Canvas
Thanks for the reply. I have pretty much given up on getting this to work in the way I think it should. Of course how I think things should happen isn't how they do happen. Here's basically how it works, but it seems to be off by a pixel in some cases and the circles seem to be missing sections when things land on some boundary conditions I have yet to figure out.
Personally I think this is unacceptable to be inside application code and should be in the Android libraries The only way I know of to do custom vector graphics on the fly in Android is to draw everything into an image file and then put that into an ImageView.
As far as changing the coordinate system, I doubt that is possible although I haven't researched it. It might be fairly trivial to write a function that would map your data's system to the standard Android coordinate system, though.The CanvasRenderingContext2D.
This example uses the isPointInPath method to check if a point is within the current path. Whenever you move the mouse, this example checks whether the cursor is in a circular Path2D path.
If yes, the circle becomes green, otherwise it is red. Get the latest and greatest from MDN delivered straight to your inbox. Sign in to enjoy the benefits of an MDN account. The compatibility table on this page is generated from structured data. Safari iOS? Last modified: Oct 30,by MDN contributors. Related Topics. CanvasRenderingContext2D Properties element.
Learn the best of web development Get the latest and greatest from MDN delivered straight to your inbox. The newsletter is offered in English only at the moment. Sign up now. Sign in with Github Sign in with Google. Chrome Full support Yes. Edge Full support Firefox Full support 2. IE Full support Yes. Opera Full support Yes. Safari Full support Yes. WebView Android Full support Yes.
Chrome Android Full support Yes. Firefox Android Full support 4. Opera Android Full support Yes. Safari iOS Full support Yes. Samsung Internet Android Full support Yes. Firefox Full support