title: Improve quality of programmatically captured image in the android app
body: <p>I integrated camera in my application and using that camera the captured image is blur. Any suggestions for improving captured image quality.
  I am using multipart for sending image on server.</p>
  
  <blockquote>
    <p>Code Snippet</p>
  </blockquote>
  
  <pre><code>@Override
  public void openCameraAction() {
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      startActivityForResult(intent, CAMERA_REQUEST);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == Constants.CAMERA_REQUEST &amp;&amp; resultCode == Activity.RESULT_OK) {
          photo = (Bitmap) data.getExtras().get("data");
  
          imageBase64 = encodeToBase64(photo);
  
          imageUri = getImageUri(getApplicationContext(), photo);
          imageFile = new File(getRealPathFromURI(imageUri));
  
          getImageView.setImageBitmap(photo);
  
          RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"),imageFile);
          MultipartBody.Part image = MultipartBody.Part.createFormData(imageQuestionId, imageFile.getName(),requestBody);
          parts.add(image);
      }
  }
  
  public static String encodeToBase64(Bitmap image)
  {
      Bitmap immagex=image;
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      immagex.compress(Bitmap.CompressFormat.PNG, 100, baos);
      byte[] b = baos.toByteArray();
      String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
      return imageEncoded;
  }
  
  public Uri getImageUri(Context inContext, Bitmap inImage) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
      String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
      return Uri.parse(path);
  }
  
  public String getRealPathFromURI(Uri uri) {
      Cursor cursor = getContentResolver().query(uri, null, null, null, null);
      cursor.moveToFirst();
      int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
      return cursor.getString(idx);
  }
  </code></pre>