I'm looking to map an ImageView drawing rect to a quadrilateral.
I was hoping I could do this by overriding ViewGroup.getChildStaticTransformation (View child, Transformation t) and messing around with the Matrix with and without a Camera, but its not as simple as I would like.
I want be able to take a bitmap and project it onto a 3d plane / surface.
I thought I had found a nice and easy solution with Matrix.setRectToRect(...) but not quite there. As RectF only allows the edges to be specified rather than the corners I cannot use to map to a trapezium. I would like to just be able to specify my destination shape rather than mess around with 3D animation classes or manually rotating a Camera.
I know i need to brush up on my Linear Algebra but I'm hoping someone can give me some pointers :)
Thanks!
EDIT: looking around I see I want to use a Projective Transformation
EDIT: I'm going to test out this solution
Doh, its Matrix.setPolyToPoly() that i was looking for! It was there the whole time, since API level 1 (thank god!)
Related
I've been searching for simple example and solution in stackoverflow, but I couldn't find one. So, I'll ask a new one and my apologies if this question have been asked before.
First, I want to make an apps that draw a Japanese Kanji Stroke using bezier curve, I already have 1 starting point, with 3 curves, for example :
M(11,54.25)
c(3.19,0.62) (6.25,0.75) (9.73,0.5)
c(20.64,-1.5) (50.39,-5.12) (68.58,-5.24)
c(3.6,-0.02) (5.77,0.24) (7.57,0.49)
What I have been found during searching in internet is, it looks like I could use Path.cubicTo() and use canvas as to draw it (using canvas.drawPath()).
And also, I want the canvas to draw it using animation at given frame rate or speed.
Anyone could give me a simple example or maybe some clue or anything that I can work with ?
Thanks !
You can find great example here:
http://www.jayway.com/2012/08/29/creating-custom-android-views-part-3-animating-your-custom-views-smoothly/
The sources are also there so it's very easy.
Your approach is good- you basically use Path.cubicTo in your View's onDraw and invalidate views while changing input coordinates. You can do it in another thread or create ValueAnimator and invalidate view in AnimatorUpdateListener.
I m working on canvas. Here I just want to draw some geometric figures on canvas which may be resized according to the touch_move positions. By figures , I just meant triangle,rectangle,circle and some polygons. Is there a way to achieve this? . I haven't seen such apps which can draw these figures over canvas. So this seems to be complicated.. Thanks in advance
See this link.
If your application does not require a significant amount of processing or frame-rate speed (perhaps for a chess game, a snake game, or another slowly-animated application), then you should consider creating a custom View component and drawing with a Canvas in View.onDraw(). The most convenient aspect of doing so is that the Android framework will provide you with a pre-defined Canvas to which you will place your drawing calls.
I'm sure you can find some open-sourced out-of-the-box solutions for this if you tried a little.
If you actually want to learn something you should read the tutorials of per example;
-Custom Views
-OpenGL
After doing the tutorials, you'll have 2 ways to draw basic shapes, a triangle and a circle I believe, already done.
I'm currently attempting to make a simple 2D CAD-type viewer app for Android. Basically the input file contains a bunch of primitives (rectangles, lines, circles, octagons, that type of thing), and the goal is to draw these to the screen at whatever coordinates/sizes they offer.
My initial instinct is to use a Canvas to draw these to, using a quadtree or some similar structure to track which items will show up on the screen at any given time.
Does anyone have any recommendations here for a better way to implement this (my graphics programming experience is minimal, and hence I'm having problems even finding a starting point to Google from)?
Thanks in advance,
-Ross
That's a very broad question so my answer will only point at classes that you should be looking at.
Extend a surfaceView to be your cadView, that way you'll be all the calculation outside the main thread.
you'll still have to draw on the canvas.
from the canvas you can getWidth() and getHeight() and use those values for base comparison on your positions.
Canvas have some primitives drawings types like arc, circle, point.
Further you can use Path to draw full figures, line, filling, quadratic, etc.
for backgrounds you can create color drawables and draw it on the canvas.
and that's pretty much it.
I've got some problem. I have an image drawn using canvas, and I would like to animate it. I would like to do something like TranslateAnimation, but TranslateAnimation works only with views, and my image is not a view. What can I do?
Personally I haven't worked with Android canvas, but I am fairly certain that what you need to do is this:
Draw your shape on the canvas
Wait for a couple of miliseconds
Clear the canvas
Redraw shape to next immediate position
and repeat this until the final position is reached.
From my little knowledge the canvas is more similar to a piece of paper than to a flash animation. You need to draw, clear, recalculate, redraw. I highly recommend reading some more on the topic. Firstly, I would start with the android canvas reference: http://developer.android.com/reference/android/graphics/Canvas.html
and then try some tutorials like canvas frame by frame tutorial for android : http://developingthedream.blogspot.ro/2011/01/android-canvas-frame-by-frame-animation.html
And also I highly recommend looking up things on google first before posting a question on stack. There is a good chance, especially if you are a beginner, to find existing tutorials with everything you need and more. Good luck learning.
I want to implement an effect that, showing a picture on a bubble surface with the picture looks like surrounding the bubble surface. But I don't know how to do this kind of things...
I am doing it in Android platform, should I use OpenGL ES for this ? Or just some 2D transformation can achieve this effect ?
One more question is, I want to create many interesting graphics effects like the PhotoShop's various filter, is there any books/articles I can refer for this kind of things ? Is this kind of work belongs to the "Digital Image Processing" field or some other computer graphics related fields ?
Or just some 2D transformation
This effect is a nonlinear transformation, so doing through the 2D (linear) transformations being available will not work. You can do it using OpenGL by numerous ways. I'm currently thinking about some easy to understand way to convey, what you need to do. Basically you need to implement some kind of refraction or nonlinear radial warp.
Say p is the center of your bubble (in 2D), and r the position relative to p, then the undistorted picture is given by r+p. Now you want to distort it toward the edges. A parabolic distortion comes to mid, i.e. instead of r+p you'd show the pixel r + (|p|^2)*p/|p|