I'm using OpenCV to implement something simple, that if Mat has color of pixel(x,y) equal to white, it turns to transparent (alpha = 0). After that convert Mat to bitmap.
When debugging the bitmap returned is correct, but when i set it to imageview, the image returned still has white background (as in the original image) instead of the transparent image.
This is the original image (with white background)
And debugging image, with transparent background
Please help me to fix it :(
Add following line in your ImageView,
android:background="#android:color/transparent"
Related
I would like to change (map) white color to blue color. How can I do this on ImageView in Android? I tried setColorFilter by PorterDuff / LightingColorFilter / ColorMatrixColorFilter but I can't figure out how to set it up. There is a transparent background around the image.
Try to use Background Tint color function in xml or java code.
or
I would suggest another way. Take on frame layout and place view and then image view.
white portion in image should be transparent use PNG image.
and you can give color to base view color which ever you want.
Given a bitmap, I know how to make an ImageView more transparent by setting alpha. But I want to also set a white background color (different from the view its sitting on), so it appears more opaque than transparent.
Referring to the image below,
I get the left pic using , ImageView.SetBitmapImage(bitmap).
Using ImageView.SetAlpha = 0.5, I get the middle pic
but how do I get the right pic.
Also, in my axml, I have set the ImageView background color to white, but it still doesn't help...I still get the middle pic.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF" />
I solved this by wrapping the ImageView in a LinearLayout, where the backgroundcolor was set to white. Then the bitmap alpha was fine
The CircularImageView, https://github.com/Pkmmte/CircularImageView, works great when setting an image bitmap like so...
circularImageView.setImageBitmap(bitmap);
However, there are times where I just want to set a solid color instead of a bitmap. If I do something like this,
circularImageView.setBackgroundResource(R.color.blue);
The color of the view is set but the image is never made circular, so it fill the entire rectangular view. I'm assuming the getDrawable() is returning null so it can't actually manipulate the view. Anyone ran into this problem or any suggestions on what to do?
Edit:
I can do this but it seems a bit flimsy:
Bitmap image = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
image.eraseColor(android.graphics.Color.GREEN);
circularImageView.setImageBitmap(image);
You should call circularImageView.setImageResource(R.color.blue) instead.
The code you wrote sets the background of the view, not the content image. Looking at the code on github, this view will only clip the content image to the circle--it has no effect on the background at all.
Give a try for ColorDrawable;
int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);
How to change TRANSPARENT part of image set in imageview with another image?
Below is the main image, there is TRANSPARENT portion(here looks white), i want to set another image withing that portion of image.
any idea how to do it?
Question:
How to find TRANSPARENT portion starting point LEFT(x,y), RIGHT (x,y), BOTTOM LEFT (x,y), BOTTOM RIGHT(x,y) ? for image replacement.
How to process bitmap in runtime to add another image to make changes in imageview?
I've tried this to find transparent part of image.
You have a bitmap (B1) and there is only one rectangle transparent zone somewhere. And you want to place another bitmap (B2) inside it.
use monte-carlo method to find any transparent pixel on B1. You know
it's coordinates now.
go [left/right/top/bottom] from transparent pixel and find
first solid pixel. Now you know transparent rectangle coorditates.
There are several ways to put something inside transparent area. You can:
place second imageview (with B2) under the first one (with B1). Set B2 padding inside imageview accordingly transparent zone coordinates.
create new image from B1 and B2 and set it to imageview.
do it some other way...
try this example in this crop image with transparent part it will use full for you.
https://github.com/ketanpatel25/Image-Cropping-In-Transparent-Area
I try to show a simple bitmap with below code snippets.
imageView.setImageBitmap(bitmap.extractAlpha());
ImageView visible as empty.
If your original bitmap is opaque then extractAlpha will return a mask that is basically black.
By default your view's background is black so in your case you are setting black on black which is why you can't see it.
Try setting your background to white and see what happens. Something like this:
imageView.setBackgroundColor(Color.WHITE);
imageView.setImageBitmap(bitmap.extractAlpha());