There are many curious things in android.
The thing that I want to ask is about Drawing with canvas.
when I override ondraw function ,
and the android gives me canvas to draw something in device.
I would like to get answer how canvas draw image or some figures internally.
If they need to draw something, use surface flinger or openglES or core graphics or any
thing to swap image from back buffer to front buffer in device display.
I got some similar answers in this link Android GUI architecture - relation between Surface/view/window/canvas
But it's not really enough to understand..
Because I can't understand how they can initialize the device display and draw canvas in device display
I understand what relationship is in ViewRoot and View also surface.
Please let me know keys to draw something deeply about native layer.
I strongly suggest you load the API Demos app into Eclipse and look through the Graphics demos. There are a large number of them and the code should give you insights into solutions to your problem.
To load the API Demos app, in Eclipse click File > New > Other > Android Sample Project.
Then select your build target such as Android 4.2.
Then from the list of sample apps select the API Demos app.
And finally click Finish.
There are over 300 demos in the app, so it can be difficult to navigate. You want to look in the Graphics section.
It's a little unclear from your description exactly what your issue is, but the API Demos cover a lot of territory and you should be able to find some code to help you out.
Here is a list of some of the Graphics API Demo Java source files:
AlphaBitmap
AnimateDrawables
Arcs
BitmapDecode
BitmapMesh
BitmapPixels
CameraPreview
Clipping
ColorFilters
ColorMatrixSample
Compass
CreateBitmap
DensityActivity
FingerPaint
Layers
MeasureText
PathEffects
PathFillTypes
Patterns
Pictures
DrawPoints
PolyToPoly
Regions
RoundRects
ScaleToFit
SensorTest
SurfaceViewOverlay
WindowSurface
Sweep
TextAlign
TouchPaint
Typefaces
UnicodeChart
Vertices
Xfermodes
Related
I'm working on a university project in which I need to visualize on a smartphone datas from pressure sensors built in an insole.
I need to draw on a View, as a background, a footprint, something like the image below but just for one foot.
I don't want to use a static image because with different screens resolution it could lose too much quality, so I'm trying to do it by code.
The main problem is that I'm not very skilled in graphic programming so I have not a smart approach to this problem.
The first and only idea that I had was to take the insole's CAD representation, with its real dimensions, scale it in function of screen's ones and put it together using simple shapes (arc, circle, ecc...) available in Android.
In this way I'm creating a Path which will compose the whole footprint, once I will draw it with a Canvas.
This method will let me to do the work but is awful and needs an exceptional amount of work and time to set every part.
I have searched for some similar questions but I haven't found anything to solve my problem.
Is there (of course there is) a smarter way to do this stuff, saving time and energies?
Thank you
of course, you can always use open gl es
this method might not save your time and energy but will give you a better graphic and scope to improve it for later purpose
the concept is to create a float buffer with all the points of your footwear and then draw is with connected lines on a surfaceView
to get started with open gl es you can use this tutorial : https://developer.android.com/guide/topics/graphics/opengl.html
and here is an example : https://developer.android.com/training/graphics/opengl/index.html
Im looking for Android 2D framework which allows me to create canvas layer on which I can draw simple shapes like rect, oval atc (raster graphics). The canvas have to PERSIST everything I draw on it.
I found many engines (libgdx, andengine ...) but if they have capability to draw shapes, its only for one screen update. Reason becouse I dont store drawn shapes to some kind of List is becouse in app, the drawing occurs every screen update so I just want to modify canvas and dont remember anything.
Thanks for every answer.
As far as I know, android doesn't support something like that. Android uses double-buffering which means 2 alternatives "screens" that alternate each other so if you draw on one the next would be on random state.
There are tricks you can use to achieve what you want like draw both screens and then stop drawing, but android doesn't support such behavior because when you get hold of a canvas it's not certain that it returned exactly as what you did last frame, it doesn't specify what could cause an error, but if you ask me it could be anything that pops up on screen.
You don't really need an engine to do that, you can use a SurfaceView and draw on it (it supports shapes like the ones you want)
OpenGL ES 2.0 is implemented in a project that I have been working on with a couple shader components that define what a texture should look like after modifications from a Bitmap. The SurfaceView will only ever have a single image in it for my project.
While doing several different approaches and looking through code in the past 24 hours, just hoping for a quick response or two from the community. Not looking for solutions, I'll do that research.
It sounds as though since we are using shaders, that in order to do scaling and movements in the texture based on touch events, that I will have have to use the Matrix utilities and OpenGL translations or movements with the camera to get the same effect as what is currently done within an ImageView. Would this be the appropriate approach? Perhaps even modify the shader code so that I have some additional input variables?
I don't believe that I can use anything on the Android side that would get the same effect, such as modifying the canvas of the SurfaceView or altering dimensions of the UI in some other fashion that would achieve the same effect?
Thanks. Again, solutions for zooming and moving around aren't necessary, just trying to get a grasp on intermixing OpenGL and Android appropriately for the task.
Why does it seem that several elements in 1.0 are easier than 2.0; ease of use should improve between releases.
Yes. You will need to use an ortho projection and adjust the extents to zoom. See this link here. To pan, you can simply use a glTranslatef.
If you would like to do this entirely in the pixel shader, you can use the texture matrix stack with glScalef and glTranslatef.
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 am trying to implement some photo effects i try different effect like sketch painting effect, Emboss effect,
and now i m trying to implement Oil Painting Effect.
i found this link
http://supercomputingblog.com/graphics/oil-painting-algorithm/
but at my level this to hard to understand plz help me in this, or any other reference link for it.
Download JHLabs Library for Android from the following link.
https://code.google.com/p/android-jhlabs/
https://code.google.com/p/android-jhlabs/downloads/list
There are the effects given for oil painting, Emboss nad many more.
You can create pencil sketch effect from DoG Filter followed by GrayScale given in the library.
I think oil paintings are simulated best using a technique called "Stroke Based Rendering" (SBR) pioneered by Aaron Hertzmann. It's been around for a long time. Whether you do this in android or any other os doesn't make much of a difference.
What you need is a function that takes a rectangle and an orientation, and place a brush stroke on the current canvas. The brush itself is defined as a set of 2 texture grayscale images: one for the opacity and one for the height. You need one for the height so that you can use create a bump map alongside the canvas (the rendered image). Now, the tough part is to get good texture maps for your brushes so that it looks realistic. That's where you need to experiment quite a bit and see what you like best. Everybody has its own idea of what looks best.
To define the rectangle and its orientation, you can use image moments. The end result is that your brush strokes will kinda follow the contours of objects, which is usually what artists do (not always though).
In any case, this methodology is better explained here (this is link to my blog):
http://3dstereophoto.blogspot.com/2018/07/non-photorealistic-rendering-software.html
You can try the software called "The Painter" which I wrote (free and works on windows 64 bit) to see what can be done using SBR. Maybe it's not what you want at all. Here's the link to the software (also includes toon shading and watercolor rendering):
http://3dstereophoto.blogspot.com/p/painting-software.html
Again, this is a link to my blog which deals primarily with 3d photography. I happen to also like painting a lot.