Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:
I tried to send three photos to the server but unfortunately it has a problem.

The procedure is such that it first takes a photo of the phone and sends it to the server as a bitmap. Do you have a process for this because it wants a file.


//for convert bitmap to base64 string
public String getStringImage(Bitmap bmp) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}


What I have tried:

//Todo: choose or take image
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      imageutils.onActivityResult(requestCode, resultCode, data);

  }

  @SuppressLint("MissingSuperCall")
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
      imageutils.request_permission_result(requestCode, permissions, grantResults);
  }

  @Override
  public void image_attachment(int from, String filename, Bitmap file, Uri uri) {

      if (from == 1) {

          bitMapImage1 = file;
          file_name = filename;
          img_one.setImageBitmap(bitMapImage1);
          String path = Environment.getExternalStorageDirectory() + File.separator + "ImageAttach" + File.separator;
          imageutils.createImage(file, filename, path, false);

      } else if (from == 2) {
          bitMapImage2 = file;
          file_name = filename;
          img_tow.setImageBitmap(bitMapImage2);
          String path = Environment.getExternalStorageDirectory() + File.separator + "ImageAttach" + File.separator;
          imageutils.createImage(file, filename, path, false);

      } else if (from == 3) {
          bitMapImage3 = file;
          file_name = filename;
          img_three.setImageBitmap(bitMapImage3);
          String path = Environment.getExternalStorageDirectory() + File.separator + "ImageAttach" + File.separator;
          imageutils.createImage(file, filename, path, false);


      }


  }
Posted
Comments
Richard MacCutchan 4-Oct-21 7:03am    
The server needs to convert the Base64 data back to its original Byte array, and thence to a bitmap.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900