我想顯示圖像從服務器的特定id如果圖像存在。如果沒有圖像的id,我想顯示一些默認圖像,然後我想從相機捕捉圖像,剪裁它,然後將該圖像加載到服務器,並且我想在第一個活動中顯示該加載的圖像。如何才能做到這一點。我嘗試了一些代碼,但如果服務器中沒有圖像,它會顯示一個默認圖像,但它不會被第一次上傳的圖像取代。如果我再次登錄,它將顯示。如何解決這個問題?用android上傳的圖像替換默認圖像
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_details);
{
String IMAGE_URL = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name;
new DownloadImageTask((ImageView) findViewById(R.id.ProfilePicIV))
.execute(IMAGE_URL);
}
public void onResume()
{ // After a pause OR at startup
super.onResume();
getIntent();
String auid_num = auid_s.getText().toString();
String imei_num = imei_s.getText().toString();
String img_name = getIntent().getStringExtra("img_name");
String img_path = getIntent().getStringExtra("img_path");
//Refresh your stuff here
SendDataToServer(auid_num, imei_num);
String IMAGE_URL = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name;
new DownloadImageTask((ImageView) findViewById(R.id.ProfilePicIV))
.execute(IMAGE_URL);
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
xml:
<ImageView
android:id="@+id/ProfilePicIV"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="@drawable/default_image"
android:scaleType="fitXY" />
哪裏是你的'DownloadImageTask'方法? –