Draw/create vector images from app - android

I need users to be able to draw and type on a vector image. The user shall also be able to resize and move paths/texts so the "elements" needs to be able to receive click/touch events.
The problem is that I don't know how I should draw them on screen to be able to handle the events and save the result. Canvas doesn't seem to let me do that.
Anyone that can lead me to the right track?
The only thing I can think of is a WebView and develop the hole thing using JS and SVG. But that doesn't feel right...
I will use a API level of at least 11 but up to 13 is okay.

You could have one big AndroidGraphics stretched on the screen and catch all the touchDown Events, which give you coordinates and decide for yourself what to do with them.
Try libGdx framework which has already implemented most details for you (plus it runs GL Es)

Related

Android camera zoom in specific region

is it possible to automatically traverse a surfaceview doing zoom in operations?
Specifically:
-Divide a surfaceview in a grid.
-Do zoom in of each grid without any user gesture.
Thank you for your help.
Depending on the android in question it may very well be possible, however to be able to do this would require you to be able to run processes alongside the camera if you are looking to do this "live" it may well be easier and effectively simpler to use an image taken on the camera and then perform the given operation you desire.

Techniques for tiling and zooming of large bitmaps

I've been working on an android app that tries to accomplish the following:
- Download large images from a service (about 4000px x 4000px)
- display these images and let the user zoom/pan
- draw overlays to show additional information
So far I have been somewhat successful by loading a scaled down version of the image and use that for panning and zooming, using BitMapRegionDecoder to load a high res representation of the current viewable area once the panning/zooming has stopped.
While this seems to work, I have realised that I'd need to put a lot of time in it to make everything smooth and stable, also I have got a hunch that a tile based approach will yield better performance. So my question is, can anyone point me to some lib or resource that will let me unload some of the work in an standing on the shoulders of giants approach :)
Thanks
I'm a bit late here, but I faced this problem and this answer might help others. I've recently developed an open source library that splits a large image into small tiles, showing only the visible ones. It also handles zoom/pan/double tap gestures. The source code and samples are available at https://github.com/diegocarloslima/ByakuGallery

How to fix intermittent/jerky android paint updates

(I tried to stuff the question with keywords in case someone else has this issue - I couldn't find much help.)
I have a custom View in Android that contains an LED bargraph that displays levels received via socket communication. It's basically just a clipped image. The higher the level, the less clipped the image is.
When I update the level and then invalidate the View, some devices seem to "collect" multiple updates and render them in chunks. The screen visibly hesitates for say 1/10th of a second, then rapidly paints multiple frames, and then hesitates again. It looks like it's overwhelmed and dropping frames.
However, when changing another UI control on the screen, the LED bargraph paints much more frequently and smoothly. I'm thinking Android is trying to help me by "collecting" multiple invalidations and then doing them all at once. Perhaps by manipulating controls, I'm "increasing" my frame rate simply by giving it "more to do" so it delays less between actual paints.
Unlike animation (with smooth transitions) I want to show the absolute latest value as quickly as possible. My data samples aren't faster than 10-20fps anyway.
Is there an easy way to "force" a paint at certain points, or is this a limit of how Views work? Should I be implementing this in a SurfaceView instead? (I have not played with that yet... want advice first.) Thanks in advance for suggestions.
(Later that same day...)
Update: I found a page in the Docs that does suggest implementing my widget as a SurfaceView is the way to go:
http://developer.android.com/guide/topics/graphics/2d-graphics.html
(An hour after that...)
SurfaceView seems overkill for what I want to do. The best-practice method is to "own" the whole canvas, but I have already developed the rest of my controls and layouts and they work well. It must be possible to get some better performance with what I have, especially since interacting with the UI makes the redraw speed satisfactory.
It turns out SurfaceView was the way to go. I was benchmarking on an older phone which didn't help. (The frame rate using a standard View was fine on an ASUS eeePad). I had to throw away some code, but the end result is smoother and faster with SurfaceView. Further, I was able to re-use more code than I expected and actually dramatically simplified my multitouch handling code (since everything I want to touch is in the same SurfaceView.
FYI: I'm still only getting about 15fps on Droid X, but half of the CPU load appears to be data packet processing. The eeePad is doing almost 40fps now -- and my data rate is only 20 samples/sec.
So... a win I guess. I want the Droid X to run better, but it flies on a real tablet.

Drawing on bitmap vs directly on canvas

In my application I need to draw a large network (basically, little boxes connected with lines) and the user will be able to zoom and pan it around.
My first option was to draw the network directly to the canvas, but I thought that was not very efficient, because each time a pan event occurs, the drawing process begins again.
So I tried to use a large mutable bitmap and draw my entire network only once (or at least whenever zoom occurs), and blit the necessary areas to the canvas.
My problem is, since the network is rather big, I get OOM exception when creating the bitmap…
What should I do? Draw directly to the canvas? Use several smaller bitmaps?
Thanks,
Direz
My first question to you is how many sprites you have going at once? By far, the fastest mechanism for having many sprites on the screen is to use OpenGL due to the hardware accelleration. The besy way, on Android, I have found to do this is to use the Cocos2d android (not to be confused with the ios version) which is available on Google Projects. You will have to use the IOS documentation in order to understand it though and there are a few decent tutorials to get started with online..in particular, the hello world template here... Www.sketchydroide.com/Blog/p?=8. It is out of date compared to the latest IOS cocos2d but thats to be expected. I have found that the programs run MUCH faster when not connected to an active debugger session in my experiments.
If you want to stick with your current approach or the above is still not fast enough, you are going to have to attempt to cull any drawing which does not appear n the screen meaning a general function of the form "if the sprite's x and y values are outside the bounds of the visible area, dont draw it" which is basically how most tile base games handle the issue.
It sounds like you are doing the drawing manually if you are doing little squares. I think it is more adviseable to go ahead and draw on the canvas but to be very careful about managing your sprite counts and to avoid heavy for loop iteratiins that occur on
the frame update loops where possible. It is rather easy to max out your little handset with drawing operations.
Another option might be to draw the entire bitmap once into memory and then use a copy rectangle operation to transfer the image to the screen without drawing the full bitmap you have created. I think that copy rect should be a fast operation normally but if you are using it to draw the whole screen it seems like overkill and probably wont work as well.
You're probably not going to like this, but if all you're doing is drawing boxes and lines, the efficiency of the canvas is going to be pretty dang high. Are you getting UI lag or something?
One thing I have messed around with is drawing collections of subcomponents that won't change much or at all to a bitmap then rendering (scaling/moving aren't all that expensive if done at the right level) to the canvas can help efficiency. I have tried in the past to create a framework for rendering a tile-like subset of an existing larger image, but did not meet much success. I've made things work, but the code just gets ugly.
Oh, also a quick test to see if the component you are rendering is within the rectangle created by the screen can save you a bunch of processor time.

Scaling an android View

ok, I'm going to ask this because I really can not find an answer, after scouring for hours.
I'm making an android game, and I have a gameboard 'view'. My gameboard view has a few things - it has a background image, and then it has a grid of board pieces ontop of it.
I want the user to be able to double tap to zoom in, and then pan around the board.
I've been able to apply a transform in the past to get this effect (on other platforms) but I'm not sure how to do this in Android (I'm still new) - does anyone know how to apply transforms or achieve the above effect, WITHOUT me having to calculate the position of everything in my view?
Please dont suggest Canvas - I want my game pieces to be objects, and I want to be able to listen for 'on touch' events (AKA I do not want to have to figure out what the user touched when they touch the screen). I also want this for Android 2.1+
Thanks for any help ahead of time!!
Unfortunately doing this with views does require recalculating sizes and seems very tedious. I'm sure you know that Canvas has various matrix transformations one can apply.
If this functionality is important to you, I would think that figuring out how to have your Canvas objects receive touch events is the easier of the two paths, given that most games using the Canvas will also be receiving touch events and correlating them with the underlying game models.

Categories

Resources