Ive been trying to implement a limit to prevent the user from scaling the image too much in my multitouch zoom app. Problem is, when i set the max zoom level by dumping the matrix, the image starts to translate downward once the overall scale of the image hits my limit. I believe it is doing this because the matrix is still being affected by postScale(theScaleFactorX,theScaleFactorY,myMidpointX,myMidpointY) where theScaleFactorX/Y is the amount to multiply the overall scale of the image (so if the theScaleFatorX/Y is recorded as 1.12, and the image is at .60 of its origional size, the overall zoom is now .67). It seems like some sort of math is going on thats creating this translation, and was wondering if anyone knew what it was so i can prevent it from translating, and only allow the user to zoom back out.
Still unsure how postScale affects translation, but I fixed it by having an if statement saying as long as we are within the zoom limit i set, post scale as normal. Otherwise, divide the set zoom limit by the saved global zoom level recorded on ACTION_DOWN and set the scale so it will keep the image at the proper zoom level
Related
I'm building a solution in which there is an image shown on the app and if the phone is pulled closer to the user, the image zooms-in and if its pushed away, the image zooms-out.
I tried using a lot of acceleration detector apps to understand the values. I could see that the movement is pretty much on z axis.
Now I'm stuck at building a scale factor (to zoom in or zoom out image) from this acceleration value. Please help.
I have a code which zooms and pans the imageview matrix, it works well but i want the imageview to not be zoomed smaller than my screen, and i don't want it to be zoomed very much, i want to set a limit for zooming and to the same thing for dragging(panning) it should pan horizontally if image's width is larger than screen, and it should pan vertically if image's height is larger than the screen, how can i achieve this result ? i tried some methods from mike Ortiz's but i couldn't get them to work.
I coded this for my app, and it's tricky to get it all right.
I created some Rects and RectFs to do a lot of the interim calculations right off the bat. It's more efficient when you don't have to allocate these on every operation.
I used Matrix.setRectToRect() to find the minimum scale factor, and 3x that for the maximum. Then after the postScale on zoom, I clamp the new [absolute] scale factor to min/max.
Also after the postScale, I also compare the rect coordinates to the screen coordinates and add a translation to keep the image corners outside the screen boundaries. This same logic is also done for dragging operations.
look into this library
https://github.com/davemorrissey/subsampling-scale-image-view
Highly configurable, easily extendable view with pan and zoom gestures for displaying huge images without loss of detail. Perfect for photo galleries, maps, building plans etc.
I am drawing an image in android using canvas.
I'm using surfaceview's ontouch method to let the user scale and move the image.
I can already limit the scaling but I have a problem limiting the translate.
I can limit translate only if the scale of the matrix is in its original form, but if the
scale is changed I'm having a problem limiting its translation.
I am trying to emulate point sprites in Android using OpenGL, specifically the characteristic of the size staying the same if the view is zoomed.
I do not want to use point sprites themselves as they pop out of the frustum when the "point" reaches the edge, regardless of size. I do not want to go down the route of Orthographic projection either.
Say I have a billboard square with a size of 1, when the use zooms in, I would need to decrease the size of the square so it looks the same size, if the user zooms out, I increase it. I have the projection and model matrices to hand if these are required as well as the FOV. My head just goes blank every time I sit down and think about it! Any ideas on the necessary algorithm?
Ok, By changing field of view to zoom into the environment I divide the quad size by (max_fov / current_fov). It works for me.
I am trying to make an app whereby a picture will be shown, there're a few objects that user needs to identify (i.e. a cup), by touching the cup in the picture on the screen, a circle will be drawn if it's valid.
So far, I have a surfaceview with a bitmap as drawable to be displayed full screen, and upon touching the screen, a circle will be drawn to the view.
I could only think of getting the coordinate of the cup manually in the picture(hardcoded), and check it against the coordinate from touch event.getX() and event.getY(). But this would not work as screen resolution changes.
What is a better way in doing so? It's like I'm trying to find a way to precisely allow touch on certain areas which I've defined in my app.
You can store the coords as you were suggesting but adjust them based on the size of the SurfaceView vs. the size of the BitmapDrawable. For example, if you know a given area is 100px from the left, you could take your scale as surfaceView.getWidth() / bitmapDrawable.getIntrinsicWidth(). Multiply your scale times your value (100px) to get the final position. If you're keeping the same aspect ratio on the image, you need to get your scale from the larger of the two (width vs. height) and use that same scale for height and width.
In a given resolution, is the location of cup fixed or it varies there as well.
Also, what about the orientation (landscape, portrait)? does the location change accordingly as well?
There are standard resolutions, so you can always think of mapping the location with resolution.
Also, you can get X, Y coordinate and check if it falls within a range based on height and width of cup image.
First of all find out the size of screen (screen dimensions).
Now place objects relatively corresponding to your screen area.
eg. keep cup on SCREENWIDTH - 60 and check coordinates of touch similarly.