Miller
Miller

Reputation: 744

remove white background of image in android

I added an innerimage inside a framelayout in android.But the thing is that i am getting a white colour background.I need to remove that white colour Background.Any help will be appreciated.....

Screenshot is given below

enter image description here

xml file is given below

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView  
        android:id="@+id/imageView"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:scaleType="center"
         />

    <ImageView
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left"
        android:background="@null"
        android:maxWidth="-5dp"  
        android:maxHeight="-5dp"
        android:src="@drawable/driveimg"
         />

</FrameLayout>

Upvotes: 2

Views: 14003

Answers (2)

SUBHAJIT ROY
SUBHAJIT ROY

Reputation: 41

You can try this

// Load the image
Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.your_image);

// Define the background color to remove (example: white)
int backgroundColorToRemove = Color.WHITE;

// Create a copy of the original bitmap
Bitmap modifiedBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true);

// Iterate through each pixel
for (int x = 0; x < modifiedBitmap.getWidth(); x++) {
    for (int y = 0; y < modifiedBitmap.getHeight(); y++) {
        int pixelColor = modifiedBitmap.getPixel(x, y);
        if (pixelColor == backgroundColorToRemove) {
            modifiedBitmap.setPixel(x, y, Color.TRANSPARENT); // or set to another color
        }
    }
}

// Set the modified bitmap to an ImageView
imageView.setImageBitmap(modifiedBitmap);

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

you can either set the background to null (android:background="@null") or use a transparent color (android:background="@android:color/transparent")

Upvotes: 5

Related Questions