See below image and it contains some black outline and i want get only those outline. means all other part of image should be invisible.
how can i achieve this?
I'm thinking is it possible to identify a colour and invisible other colours?
You can make all other colors transparent using PorterDuffXfermode
It looks as if in your case this may not be enough, as you have black regions in the photo. One option is to change the color of the black regions to a very dark gray before adding the lines.
Related
I have an ImageView and a TextView. They both use ?attr/somecolor to see what color they have to use depending on what theme is selected. This somecolor is either black or white depending on theme.
Now when I say they both need to be red using R.color.red, the TextView has a more brighter red then the ImageView.
sometext.setTextColor(ContextCompat.getColor(this,R.color.green))
someimage.setColorFilter(ContextCompat.getColor(this, R.color.green))
Is there any reason why these colors don't match up?
For what it's worth, here's what I get for an ImageView with app:tint="#color/black and a TextView with android:textColor="#colorBlack, and then
someText.setTextColor(Color.RED)
someImage.setColorFilter(Color.RED)
It's hard to say exactly what you need to do, but there are two different things going on here. For the TextView, you're literally just telling it what colour to draw with. That should always come out looking how you expect.
But for images, it's a little more complicated. You're applying a tint over existing image data, which interacts with the original colours and alpha to produce a final mixed image. For a bitmap image, that colour is in the individual pixels. For a vector drawable, it's in attributes like the fillColor.
For example, that fill colour on the arrow is #color/white, but here's what happens if I knock the alpha down by setting android:fillColor="#AAFFFFFF":
You can see the colour is different - it's actually partially transparent so it's blending with the white background. Applying full-alpha red over it didn't change the overall alpha - and it can't really, it's the alpha that says which parts of that square image are "empty" and which are "the arrow". (Well, you can do that with a different PorterDuff mode, but by default it doesn't!)
The alpha of your tint matters too - here's a partially transparent tint applied to the #color/white arrow (and the text):
someText.setTextColor(Color.parseColor("#99FF0000"))
someImage.setColorFilter(Color.parseColor("#99FF0000"))
And here's the same tint applied when the arrow's fill colour is #color/black
So the colour tint, when it's partially transparent, only really shifts the overall colour appearance, rather than fully replacing it. So check your R.color.green value and make sure it's actually fully opaque. If it's not, and that's how you want it, then pay attention to the fillColor you're using - you can see there that I'm applying the exact same colour to the text, but it matches more closely when the arrow is white
The other thing is the different PorterDuff tinting modes you can apply with setColorFilter - I can't really go into them right now (some info here and here) but you can control how the tint colour and the image are composited, how they're blended together.
Ideally you'd just make your image's fillColor white and apply your tint to it and call it a day, but if you can't do that (because it's in use elsewhere) or you need to tint bitmaps, you can look into that stuff!
Instead of using the ?astr which is for the main portion of the app user interface example navbar and things like that. You can create your color as Third Primary Color and just call it from there. I only use the ?astr for main color of the title bar or nav bar.
When you define the color as a third primary define the same color in both themes. You should get the same color for both. I do this a lot on all of my apps.
Also Android Studio is yelling at me saying that the ?astr is no longer needed. So I have a feeling that it will be done away with in the future.
Also defining your own colors will ensure the colors are the same. Be sure to set the same #13345fg(not actual color) with both themes that are pre-built for the app.
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.
I'm working on a little side-project that uses images with only grey-hues and no colors. I was wondering if it's possible to throw something like an opaque (is that the right word?) 'filter' or 'layer' over these images to color them according to the strenght of the Grey color.
Say I want the images to be blue, do I get the pixel-data and up the 'B', or is there an easyer way?
Basically what it boils down to is this: Everytime the app starts, a different color is selected (Orange, Blue, Green, Pink, etc.) and thrown over the grey images. But how does one achieve this?
-Zubaja
As #DerGolem mentioned above, if you want to do it programmatically, it looks like one of these tutorials could help you solve your problem:
Example to apply ColorFilter on ImageView
Swap color using ColorFilter
However, there might be an easier way. I haven't tried this myself, but this is what I would do:
In Gimp, or some other photo editor, convert the grey in your images to alpha (transparent). Then put your image in an ImageView in a FrameLayout. At runtime you can programmatically set the background color of the FrameLayout. Whatever color you set should show through the transparent areas of your image, making it look as if you changed the image color.
You'll have to apply it pixel by pixel.Pretty much like you already mentioned.Look here for inspiration:
Image Editing Filters Tutorials
Scroll down to "Android: Image Processing"
My Drawables have a transparent background with an white icon in the middle. What I want to do is programatically color ONLY the white part and leave the transparent pixels untouched.
I've tried lots of different methods but I always end up with a Drawable that is completly colored.
Does anyone know how to go about this?
Cheers
I don't know whether it will suit your requirement, but please split the one image with two, one full background transparent image and other is single white image icon and put this on the centre of the layout and change only that imageicon's color.
I have an circular image.It is displaying in list view.In every item of list view there is one text and this image.This circular image has one color.How can i make some portion of this image covered with any other color.Any help will be appreciated.
Make sure the image you have is on a transparent background. Then, cutout a portion of the image which you wish to change colour. Then, in your program call setBackgroundColor(int myColor) and the colour you set will show through.
Edit: Using Photoshop, or your favourite image editing program, prepare your image by ensuring it is on a transparent background. Then cutout the part which you want to change colour. Save the image in your drawable-hdpi folder in your Android project. Then, set the background colour to the colour you want and it will show through the cutout e.g.
ImageView icon = new ImageView(context);
icon.setId(1);
icon.setImageResource(R.drawable.paint_splat);
icon.setBackgroundColor(pickedColour);
In the example above, my paint_splat image shown below:
the white areas are not white - they are translucent. If you don't know how to do this, you need to read up on image editing in whatever image editing program you will use.
Then the last call :
icon.setBackgroundColor(pickedColour);
Sets the background colour but this can only be seen through the translucent part of the image and so it changes the colour, in my case, of the paint splats.
Also, if the colour you use for the foregound matches the main screen colour of your application, in my case the splat image has a black colour foreground and my Android app has a black screen, then ONLY the coloured paint splat is visible so it looks like the whole image is changing colour.
If you want to change background colour of image at run time ......
then use this simple code...
it working nice....
final ImageView image=(ImageView)findViewById(R.id.image_view);
int number1=(int) (Math.random()*255);
int number2=(int) (Math.random()*255);
int number3=(int) (Math.random()*255);
int image_colour=android.graphics.Color.rgb(number1, number2, number3);
image.setColorFilter(image_colour);