How can I get the transparent region in an image in android?
My problem is that I have images with transparent areas and I need to let the user click on regions and handle the click event only when they clicked on the actual colored regions of the image. How can I do this in android?
I saw that Drawable Has a getTrasnsparentRegion method but the default implementation returns null. So I need to overwrite it and put this implementation there.
Thank you,
If you used a bitmap you could then call getPixel(x,y) using the coodinate information provided from the click. I think getPixel returns an argb color value, you could then use this to see if that pixel is transparent.
Maybe there is a web api where you can send it an image and it will clear out white space, maybe picnik.
I know android apps can use each other, maybe find an app that can make white space transparent, though I doubt there is one with magic wand like capabilities. I know you would need to get at the developer of the app.
Related
I am working on an Image editing app, I have done almost everything that is cropping, re-sizing, filters e.t.c but I cannot seem to really figure out how I can remove image background,the basic idea is the image will have a distinct background e.g subject can be grey and background white or vice versa, I tried looking up here and other sites but could not really find anything matching my description the closest thing was to use OpenCV which did not really do the job well, for the most part it was slow (using GrabCut), if anyone has tried this before or knows how to please help thanks in advance.
You can iterate over your bitmap through all pixels. And check if pixel color value is near in color value of your established background color. And change those pixel color values to transparent etc.
Edit: this answer may be useful
I have an image in my assets folder on which I am drawing stuff using an external program and then using them in my app. The problem is that the bitmaps are blank (transparent) with black and white objects in them. Note that the objects are created with Anti-Aliasing on to look better. I know this was asked before but I couldn't find what I want. I need to replace all the black and white pixels in the image (even the transparent anti-aliased ones!) to the colors given by the user. Below are some images to show what I want to do:
Please note that this is just an example and I have even some very complicated shapes and the final colors aren't known (as inputed by the user in RGB style).
Any help is appreciated. Thanks! :)
Usually you can tint the images you load apliying them a color at runtime.
The problem is that color applies to the whole image and it only matchs exactly the same color in white pixels, with or without alpha.
So you could separate all the areas of the image with the same color, save them as white and then tint them at runtime while overlapping one over another.
It depends on the framework you are using.
In an Android app, I would like that the user choose or take a picture of him from / with his device and then replace the background by another one (for example an awesome beach).
I'm looking for a library that can cut out the original picture background (the original background can be a color or maybe a landscape). Or maybe a library that can give me some tools to draw the part of the picture to keep / remove.
If a such library does not exist, I think that the "pixel replacement" method is the best way if the original picture has a color background (for example, I look for all the black pixel and change them with a transparent pixel).
I have found this tutorial but as you can see the result is not perfect. Is there a way to do not check only one color but a range of colors ? Is there a way to define programmatically the range of colors to check ?
Thank you in advance for your tips and links !
User can select some images to the screen, and be able to select/drag/move/zoom/rotate each image. When an image is selected, it will have a blue border. And user can also bring an image to the front or background.
Here is sample picture in the following: there are two images(girls) on a star-background. The top one has been selected(it has a blue border).
I don't know have to implement it. For several days of learning, I can now drag/move/zoom/rotate a single image(inside an imageview, and scaled by matrix). But I don't know how to handle multi-images.
I want to know:
Is it still a good idea to use ImageView(for each image), or what classes should I use?
How to implement the orders? (so I can bring them to front or background)
How to determine which image has been selected
How to find and draw the border of selected image?
For now, I just know how to use ImageView, but I'm not sure if I can use it to implement this task. Please give me some advices, thanks !
Drawing everything directly onto a Canvas is one way of doing it. There is an article that covers the basics of using a Canvas. You can read it HERE
There is one major downside in doing this - you have to handle all the input events by yourself. The API won't tell you which image has been clicked, or dragged. You'll have to implement that by yourself.
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?