diff --git a/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java b/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java index 8e5f0b5..bc85096 100644 --- a/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/SignupActivity.java @@ -1,10 +1,15 @@ package com.example.cosmosclient.views; +import android.app.Activity; +import android.content.ContentResolver; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Handler; +import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.Editable; @@ -23,6 +28,10 @@ import com.theartofdev.edmodo.cropper.CropImage; import com.theartofdev.edmodo.cropper.CropImageView; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -35,6 +44,7 @@ private boolean cpwEnable; private Button MakeAccountButton; private ImageView iconChoice; + private String iconImageBase64 = null; @Override protected void onCreate(Bundle savedInstanceState) { @@ -91,7 +101,7 @@ //API呼び出しのための値入力 Call call = signupService.createUser(NameText.getText().toString(), - PasswordText.getText().toString(), "https://yumenavi.info/live/2018/photo/k/s015980019.jpg"); + PasswordText.getText().toString(), iconImageBase64); //サーバからデータ受け取り call.enqueue(new Callback() { @@ -169,10 +179,26 @@ CropImage.ActivityResult result = CropImage.getActivityResult(data); if (resultCode == RESULT_OK) { Uri resultUri = result.getUri(); + //画面にトリミングした画像をセット iconChoice.setImageURI(resultUri); + + try { + //UriからBitmapの取得 + Bitmap image = MediaStore.Images.Media.getBitmap(getContentResolver(),resultUri); + + //画像をBase64に変換 + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + image.compress(Bitmap.CompressFormat.JPEG,100, baos); + byte[] b = baos.toByteArray(); + String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT); + iconImageBase64 = imageEncoded; + }catch(IOException e){ + e.printStackTrace(); + } } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { Exception error = result.getError(); } + } }