上傳的圖片替換圖片我想從我的應用程序上傳到特定的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" />
'要上傳到特定的ID圖像中server'。確定上傳到我明白的服務器。但對於一個特定的ID?不知道! '並立即顯示'。那麼要顯示圖片,您不必首先上傳圖片。如果您想立即顯示,請在上傳之前將其分配給圖像視圖。那麼會有什麼問題? – greenapps