0
我必須從用戶首選應用(Cameta,Gallery等)中選擇後上傳圖像文件。我可以在Imageview中將結果意圖顯示爲位圖。現在我想要上傳這個圖像後點擊一個按鈕。我使用改造來做到這一點。 而我按照ImagePicker類來收集圖像到我的Imageview。將位圖圖像上傳到服務器並加裝
採集圖像代碼:
CircleImageView imageViewProfile_Picture;
public void onPickImage(View view) {
Intent chooseImageIntent = ImagePicker.getPickImageIntent(this);
startActivityForResult(chooseImageIntent, PICK_IMAGE_ID);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case PICK_IMAGE_ID:
Bitmap bitmap = ImagePicker.getImageFromResult(this, resultCode, data);
// TODO collect picture and show in Imageview
imageViewProfile_Picture.setImageBitmap(bitmap);
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
要上傳圖像到服務器,我使用改裝庫
// How to get the file object from bitmap
File file=null;
RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("upload", file.getName(), reqFile);
API接口
@Multipart
@POST("/taxiapi/api?")
Call<SignUpResponse> signup(@Part("user_name") RequestBody user_name,
@Part("name") RequestBody name,
@Part("password") RequestBody password,
@Part("action") RequestBody action,
@Part("email") RequestBody email,
@Part("phone") RequestBody phone,
@Part("icard") RequestBody icard,
@Part MultipartBody.Part image,
@Part("profile_picture") RequestBody pic_name);
我的問題是如何讓文件obejct從這種情況下,在設置Imageview之後m結果意圖上傳服務器中選擇的圖片?