title: how to compress the bitmap image?
body: <p>I want to upload image to the server. Converted my image as bitmap but still getting error. Bitmap too large to be uploaded into a texture </p>
  
  <pre><code>@Override
  public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (resultCode == this.RESULT_CANCELED) {
          return;
      }
      if (requestCode == GALLERY) {
          if (data != null) {
              contentURI = data.getData();
              String[] filePathColumn = {MediaStore.Images.Media.DATA};
  
              Cursor cursor = getContentResolver().query(contentURI, filePathColumn, null, null, null);
  
              if (cursor != null) {
                  cursor.moveToFirst();
  
                  int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                  if (l == 0) {
                      imagePath = cursor.getString(columnIndex);
                  }
              }
              try {
                  Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI);
                  String path = saveImage(bitmap);
                  Toast.makeText(SignUpActivity.this, "Image Saved!", Toast.LENGTH_SHORT).show();
                  BitmapDrawable bdrawable = new BitmapDrawable(this.getResources(), bitmap);
                  if (l == 0) {
                      captureAadhar.setBackground(bdrawable);
                  }
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
      else if (requestCode == CAMERA) {
          //if (checkPermissionREAD_EXTERNAL_STORAGE(this)) {
              // do your stuff..
              if (data != null) {
                  contentURI = data.getData();
                  String[] projection = {MediaStore.Images.Media.DATA};
                  Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
                  int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                  cursor.moveToLast();
                  if (l == 0) {
                      imagePath = cursor.getString(column_index_data);
                  }
                  Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
  
                  BitmapDrawable bdrawable = new BitmapDrawable(this.getResources(), thumbnail);
                  if (l == 0) {
                      captureAadhar.setBackground(bdrawable);
                  }
                  saveImage(thumbnail);
                  Toast.makeText(SignUpActivity.this, "Image Saved!", Toast.LENGTH_SHORT).show();
              }
  </code></pre>
  
  <p>If i get picture using gallery means I am getting error as            "Bitmap too large to be uploaded into a texture"<br>
  and if i get picture using camera means getting error as<br>
  "Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=18253, uid=10257 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()"        </p>
  
  <pre><code>public String saveImage(Bitmap myBitmap) {
      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      myBitmap.compress( Bitmap.CompressFormat.JPEG, 90, bytes );
      wallpaperDirectory = new File( Environment.getExternalStorageDirectory() + IMAGE_DIRECTORY );
      // have the object build the directory structure, if needed.
      if (!wallpaperDirectory.exists()) {
          wallpaperDirectory.mkdirs();
      }
  
      try {
          f = new File( wallpaperDirectory, Calendar.getInstance().getTimeInMillis() + ".jpg" );
          f.createNewFile();
          FileOutputStream fo = new FileOutputStream( f );
          fo.write( bytes.toByteArray() );
          MediaScannerConnection.scanFile( this, new String[]{f.getPath()}, new String[]{"image/jpeg"}, null );
          fo.close();
          Log.d( "TAG", "File Saved::---&gt;" + f.getAbsolutePath() );
          return f.getAbsolutePath();
      } catch (IOException e1) {
          e1.printStackTrace();
      }
      return "";
  }
  </code></pre>