How to paint colours over a background image? - android

I've been asked to create an app that allows the user to fill in areas of an image with different colours, very similar to a childs "colour by numbers" game.
I'm not sure how to delineate the areas of the image and make them selectable. Please could someone give me an idea of a good way to go about doing this in Android.
Thanks

It's a kind of a tricky task... There's probably a better way to implement it, but here's my first thought:
You could pre-break the image into separate segments before the app runs.
As far as I know the only type of View you can create is a rectangle. But you can create many small rectangles to fill in parts of your image. Then you can get the clicks on those little areas and make a corresponding segment of your image:
int color= res.getColor(R.color.my_color);
image.setColorFilter(color, Mode.SRC_ATOP);
Hope this helps!

If you don't mind writing some NDK code, you could try OpenCV's cvFloodFill method. Otherwise you have to implement one of the image segmentation methods.

Related

9patch with custom background image

I've been working on this problem for 2 days now. What I'm trying to achieve is to make a bitmap fill the complete non-transparent background of a 9patch drawable (a speech bubble in this case).
Instead of this
I want something like this
(Yes, bad photoshopping, but serves its purpose.)
Is that even possible? I cannot provide any code, as I don't have any that would make my problem more clear. Sorry about that.
Regards,
D.

Creating a layout to draw cells with colors like in a defrag program using android

I have been looking for info about which could be the best way to draw a view like the ones shown in drefrag programs. An example con be found here.
My first attempt was to use a grid layout but it seems that could be slow for a big ammount of cells. My maximum could be between 150-200 cells.
Could anyone that has dealt with this problem share his/her experiences or suggest a better way to achieve it?.
Thanks in advance.
I would use a SurfaceView which I would draw on.
You might be able to use a TableView and change the background of the cells, but I am not sure if that is possible.

Android 9-patch image usage

OK, I've read a lot of tutorials and even downloaded some examples, but for the love of Stackoverflow, I can't get my image to stretch like I want it to and I'm hoping that someone can help me out here.
I create an image that is to be the background of a button object in Android. Here is the image:
Now, I'd like for it to stretch to the desire size of the button, whether the button is 50x50dp or 200x100dp. One thing I don't want is the border to stretch as it will look distorted, so I want to specify not to include the border, but stretch everything else to the desired size of the button.
Can someone please show me where the black lines need to go in order to achieve my goal? Do I have to change my original image in order to achieve my goal?
Thank you in advanced.
David
It's very simple using this tool Android Asset Studio: Simple 9-Path Generator. Although no matter how you do it you will have stretching and distortion due to the textured (non-patterned) background. I would stay away from that style both personally and for usability.

Advice on Putting Together a Segmented Image

I need to put together a complete image, as seen here. Each piece of the segmented tree is an individual image, but I am unsure about how I should put the pieces together efficiently with spacing in between. I've thought about stacking the images on top of each other one at a time within a canvas, but I have my doubts as to whether this is the approach that I should take. Is there a different type of container I should use or a better method of accomplishing the same task?
EDIT: just to clarify, I need to assemble the image programmatically, beginning with the base segment and eventually ending with the top segment.
If you use a program like Gimp, you can added each image as a layer, then move the layers around correctly. I'm not quite sure how you want to represent the space between the segments, transparent?
Any way after you have your image assembled the way you want you can either merge the layers or save it to a format that will flatten out your images.
I'm not sure if you want your image to be able to stretch at all or not. If so, you can save it as a .png file and then use draw9patch or equivalent to add in stretching segments. Also I'm not sure if you have to support multiple drawable sizes, if so I have a free Android app, DP Image Calculator on Google Play that might help. Just remember start with the highest resolution and work you way down to the smallest.
Hope this helps. If you have more question let me know. Have a great day.

Should I draw or load an image?

I am wondering what would be the best practice for android. To draw or to load an image?
For example I want to have a circle that is green filled with the text 25 in it.
-Should I have it in .PNG image file and just load it to the imageview placeholder when I need it?
OR should I load it in Java (by determining the position in java and load it from my res folder)?
OR Should I draw it (draw a circle, fill color, add text field inside)?
On another note, to have a checkmark, what do advise me to do?I don't even know how to draw that
I really need your help in this
Thank you so much
I'd actually argue that there is a single right answer. You should use a shape with a set color and text view inside it. It is easy to do what you've described in xml, see: Oval Gradient in Android for an example (there are a number if you google for android shapes). This will be less CPU/memory intensive than loading a bitmap, and more importantly, it will work for and look good on every screen size. As an added bonus of the user has changed their default font sizes, a textView/shape can respect that and a static image can not. Just set the background of your TextView to be the shape drawable (either in xml or programatically).
To get a bitmap to look good on multiple devices (a must for android development) , you will need a number of different versions of the same bitmap at different resolutions (XHDPI, HDPI, MDPI... etc).
Check marks are harder because they don't conform to a standard shape. Those you probably will have to make pngs for.
It depends on what you want to do.
Rendering a bitmap will be faster, but you cannot manipulate it after it is drawn.
So, for your case, you have a green circle with 25 written it. Do you also need a green ball with 23 and another with 24 in it? What about other colors?
It really depends on the amount of variation you need. At a certain point the overhead of using dozens of images will not be worth the evert of drawing to a canvas. Or, depending on how complex the images are, it will be.
The question is not "Which is better?", but instead, "Which is better for what I need to do?"
I'm not an expert on Android development but after seeing your question I have done a bit of reading and came across this article on displaying images with android that is relevant and includes some code to possibly help you out. http://www.javacodegeeks.com/2011/07/android-game-development-displaying.html
As for your image of a check mark, why dont you just go into photoshop or paint and use the line tool to draw a checkmark and then fill it in with color and save it as a .png perhaps?

Categories

Resources