[英]how to set first image into imageView from ArrayList<string>
我正在使用Pix圖像選擇器庫獲取此圖像陣列,我只想將陣列中的第一張圖像顯示到圖像視圖中。 這是我的代碼
public void uploadImages(View view) {
Pix.start(Upload_ad.this,
100,
10);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == 100) {
ArrayList<String> returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);
for (String path: returnValue)
{
String base64 = getBase64FromFile(path);
encodedImageList.add(base64);
}
}
}
您可以從編碼列表中設置base64字符串,如下所示
if (encodedImageList != null) {
byte[] decodedString = Base64.decode(encodedImageList.get(0), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
yourimageview.setImageBitmap(decodedByte);
}
您可以通過以下方式進行管理:
ArrayList<String> returnValue = data.getStringArrayListExtra(Pix.IMAGE_RESULTS);
if(returnValue != null && !returnValue.isEmpty()) {
String firstImage = returnValue.get(0);
if(!TextUtils.isEmpty(firstImage)) {
// here you will find first-image
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.