[英]Set bitmap to an image src
即時通訊試圖設置一個位圖來成像類似:
android:src="img"
但僅從代碼,而我從服務器獲取img。 但是當我執行setImageBitmap()方法時,它像在后台那樣顯示它,就像我這樣做:
android:background="img"
所以無論imageview中的圖像是不是黑色,我都不想用黑色背景,這是我得到的不好的圖像: Bad Image
我想要獲得的圖像是: 良好的圖像
如何在代碼中將位圖的圖像設置為類似於xml中的src? 很多!
這是我的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>
我的位圖對於所有圖像都工作良好,除了像這樣的圖像,其背景填充為黑色。
問題是您要設置透明圖像,並且背景填充為黑色。
檢查對類似問題的答案: https : //stackoverflow.com/a/20402227/1281775
另一種方法是在當前圖像下方創建具有所需背景顏色的另一個ImageView。
您在圖像中查看的黑色部分是透明的。 將圖像更改為非透明背景或更改背景顏色。
imageView.setBackgroundColor(color); imageView.setImageBitmap(bitmap);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.