Android - How is Canvas Used - android

I'm trying to draw circles using SurfaceView and I was curious about whether or not you always use canvas when you draw something. Are there are other ways instead of using canvas, and what are the pros/cons? Also, how would you personally draw a circle with SurfaceView?

There are two basic options: use a Canvas, or OpenGL ES.
The easiest way to draw a circle is to use Canvas#drawCircle(). Doing the equivalent with OpenGL ES is more involved, though there are various toolkits that can simplify things.
Depending on your needs, you may want to consider using a custom View instead. Canvas rendering on a SurfaceView is not hardware accelerated, but Canvas rendering on a custom View can be.

I think there is no other ways to draw instead of canvas.
You can use SurfaceView to draw any shape even a cricle also.
First you ahev to get SurfaceHolder object and using that you can draw anything.
Yo can follow these links- first second

Related

Background image working with SurfaceView

Working with a SurfaceView to make a 2d game i do not know who to put a background image in it efficiently.
I want to avoid drawing it each frame because it is an static image, any help?
The SurfaceView's Surface is a single layer. You can specify a dirty rect to reduce your draw area when you lock the Canvas, but you have to draw everything in the rect every frame -- background and all.
You could use a pair of SurfaceViews, one at the default Z-ordering, one at "media" depth. Use SurfaceView.setZOrderMediaOverlay() to do that. The layers will be composited by the system before being rendered.
If you were using OpenGL ES rather than Canvas, it'd generally be more efficient to just redraw the background from a texture each time. (If HWC runs out of overlays, that's essentially what SurfaceFlinger is doing anyway.)
See the "multi-surface test" in Grafika for an example of using multiple overlapping surfaces.

Mixing OpenGL with Canvas drawing in Android

We have Android app using hardware acceleration drawing some standard items and widgets. And also I have fancy native drawing using OpenGL. The question is, can I mix it with canvas drawing, in method onDraw for example? Does canvas preserve state or made an assumption that there is no such code?
Why do I want it. I want to have one rendering context for drawing, because two drops FPS to no more than 30.

Open GL and Canvas which method is more suitable for making custome brushes in drawing application?

I want to make brushes displayed in below image for drawing application. Which is a suitable method - Open GL or Canvas & How can we implement it?
I'd say Canvas, as you'll want to modify an image. OpenGLES is good for displaying images, but does not (as far as I know) have methods for modifying its textures (unless you render to a texture that then render to screen with some modifications, which is not always so effective).
Using the Canvas you will have the methods for drawing your brush-strokes onto the Bitmap you're painting on, in GLES you would have to modify a texture (by using a canvas) and then upload that to the GPU again, before it could be rendered, and the rendering would most likely just consist of drawing a square with your texture on it (as the fillrate for most mobile GPUs are quite bad, you don't want to draw the strokes separately).
What I'm trying to say is; The most convenient way to let the user draw on an openGLES surface would be by creating a texture by drawing on a Canvas.
But, there might still be some gain in using GL for drawing, as the Canvas-operations can be performed off-screen, and you can push this data to a gl-renderer to (possibly) speed up the on-screen drawing.
However; if you are developing for Android 3.x+ you should take a look at RenderScript, (which I personally have never had a chance to use), but seems like it would be a good solution in this case.
Your best solution is going to be using native code. That's how Sketchbook does it. You could probably figure out how by browsing through the GIMP source code http://www.gimp.org/source . Out of Canvas vs OpenGL, Canvas would be the way to go.
It depends. if you want to edit the image statically, go with canvas. But if you want after brushing the screen, to have the ability to edit, scale, rotate, it would be easier with opengl.
An example with opengl: Store the motion the user do with touchs. create a class that store a motion and have fields for size, rotation etc. to draw this class, just make a path of the brush image selected following the stored motion.

OpenGL problem on Android

I'm quite new to animations in Android. For 3D animations I have to use OpenGL to make it look more fluid.
Is it possible to convert a Drawable that is i draw some rectangle or circle on a canvas and i want that to convert into a View using OpenGL. Is that possible and if so then how?
Can anyone please let me know what does the first point in the FEATURES say in this URL http://developer.android.com/reference/android/opengl/GLSurfaceView.html
Well, you can try to convert a Drawable to a bitmap and then map this bitmap on a 3D surface in OpenGL as a texture.
OpenGL doesn't operate on that level. OpenGL is just a drawing API, giving you "pens and brushes" to draw on some canvas provided by the operating system. Any OS specific concepts like Drawables and Views are out of the scope of OpenGL and won't be dealt with by it.
However maybe if you described in detail what it is you want to achieve we may be able to help.

display transparent view over existing views

In Android 2.2, I want to display a few sprites and clickable animations over an existing view. I just discovered that SurfaceView cannot be transparent
I tried overriding dispatchDraw() of a LinearLayout but that doesn't seem to be callable via a Runnable Thread.
I also tried to extend Canvas directly, but that quickly turned into a mess when trying to place it in my XML layout.
Do I have to use GLSurfaceView to have a drawing view whose background is transparent?
Optimally, I'd like to just have a Canvas on which I can draw Bitmap at various coordinates, instead of dealing with the details of GL (unless GL is the only way I can do transparency).
Silly Rabbit. Just use Views and move them around wherever you want within a FrameLayout. SurfaceView is not designed for what you're trying to do.
I'm going to try Switching from Canvas to OpenGL and toss in parts of TranslucentGLSurfaceView.
I'm still open to selecting an answer that doesn't require OpenGL, just for the sake of it solving my original question.

Categories

Resources