이미 웹 서비스를 사용하여 문자열로 변환 된 BLOB 이미지를 가져 오는이 코드가 있습니다. 이것은 JSON 출력입니다.
{driver_name: "Anna Biendia"
taxi_plate_no: "NUV 900"
driver_contact_no: "09169271825"
driver_operator: "grab"
driver_operator_address: "987 Buendia St. California"
image: "iVBORw0KGgoAAAANSUhEUgAACDQAAAXcCAYAAADXlEzmAAAACXBIWX..."}
이것은 JSON을 가져와 레이아웃에 표시하는 Android의 코드입니다. 이미지를 제외한 다른 값이 표시되었습니다.
public class DriverDetails extends Activity {
ArrayList<Objects> objectsList = new ArrayList<>();
String url = "http://192.168.1.110:8080/taxisafe3/displays/taxidetails";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_driver_details);
new Task().execute(url);
}
public class Task extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... strings) {
String content = HttpULRConnect.getData(url);
return content;
}
@Override
protected void onPostExecute(String s) {
try {
TextView title1 = (TextView) findViewById(R.id.textView3);
TextView title = (TextView) findViewById(R.id.textView2);
TextView title2 = (TextView) findViewById(R.id.textView7);
TextView title3 = (TextView) findViewById(R.id.textView9);
TextView title4 = (TextView) findViewById(R.id.textView11);
ImageView image = (ImageView) findViewById(R.id.imageView2);
JSONArray ary = new JSONArray(s);
for (int i = 0; i < ary.length(); i++) {
JSONObject jsonobject = ary.getJSONObject(i);
Objects objects = new Objects();
objects.setDriver_name(jsonobject.getString("driver_name"));
objects.setTaxi_plate_no(jsonobject.getString("taxi_plate_no"));
objects.setDriver_operator(jsonobject.getString("driver_operator"));
objects.setDriver_operator_address(jsonobject.getString("driver_operator_address"));
objects.setDriver_contact_no(jsonobject.getString("driver_contact_no"));
objects.setImage(jsonobject.getString("image"));
objectsList.add(objects);
if (title1 != null){
title1.setText(objects.getDriver_name());
}
if (title != null){
title.setText(objects.getTaxi_plate_no());
}
if (title2 != null){
title2.setText(objects.getDriver_operator());
}
if (title3 != null){
title3.setText(objects.getDriver_operator_address());
}
if (title4 != null){
title4.setText(objects.getDriver_contact_no());
}
if(image != null){
byte[] decodedString = Base64.decode(objects.getImage(), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
image.setImageBitmap(decodedByte);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
내 코드에서 이미지가 ImageView에 표시되지 않는 이유는 무엇입니까? 미리 감사드립니다. :)
base64 를 비트 맵으로 변환 한 후
byte[] decodedString = Base64.decode(objects.getImage(), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
비트 맵을 Imageview 높이 및 너비로 크기 조정
image.setImageBitmap(Bitmap.createScaledBitmap(decodedByte, image.getWidth(), image.getHeight(), false));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다