0

im trying to set a bitmap to image something like:

android:src="img"

but only from code , and i get the img from the server. but when im doing the setImageBitmap() method it displays it like its in the background,like i would do this:

android:background="img"

so whatever isnt the image in the imageview becomes black and i dont want black background, this is the bad image i get: Bad Image

and the image i want to get is: Good Image

how can i set the image from bitmap in my code to be like src in xml ? ty alot!

here is my xml:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary">

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    android:id="@+id/profile_image"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_gravity="center"
    android:layout_centerHorizontal="true"
    app:civ_border_width="5dp"
    app:civ_border_color="#c5eaf8"
    android:elevation="10dp"/>
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:layout_centerInParent="true"/>

    <ProgressBar
        android:id="@+id/progress_bar_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_centerInParent="true"
        android:visibility="gone"/>
</RelativeLayout>

my bitmap is working good with all the images except images like this one its filling their background with black..

  • Please provide a [mcve]. Most likely, your problem lies in how you are creating the bitmap that you are using with `setImageBitmap()`. You appear to be losing the alpha channel. We can only help with that if we can see your code. – CommonsWare May 17 '16 at 17:29

2 Answers2

0

The problem is that you're setting a transparent image and the background is filled black.

Check this answer to a similar question: https://stackoverflow.com/a/20402227/1281775

Another way is to create another ImageView below the current one with a desired background color.

Community
  • 1
  • 1
Seishin
  • 1,493
  • 1
  • 19
  • 30
  • i tried , it didnt work , unless you meant to actually use a colored picture? like a blue picture in my case? anyway check my code – likesLowLevel May 17 '16 at 17:54
  • What you tried? Try the solution provided in the link I shared or just use setBackground method. – Seishin May 17 '16 at 17:55
0

The black portion you view in your image is transparent. Either change your image to non-transparent background or change the background color.

imageView.setBackgroundColor(color); imageView.setImageBitmap(bitmap);

Ashwini
  • 245
  • 1
  • 7