title: Image is getting skewed after resizing android
body: <p>Hello i am resizing the image after capturing from native camera.. image resizing is working fine but i have only one problem and that is the image is getting skewed after resizing.</p>
  
  <p><strong>here is the code that i am using to resize the image.</strong></p>
  
  <pre><code> File f = new File(Environment.getExternalStorageDirectory() + File.separator + "Bavel/" + imageName);
   FileOutputStream fos = null;
   try {
      fos = new FileOutputStream(f);
      if (orientation == ExifInterface.ORIENTATION_UNDEFINED) {
          saveByteArray(fos, getBytesFromBitmap(loadedImage));
      } else {
          saveByteArrayWithOrientation(fos, getBytesFromBitmap(loadedImage), orientation);
      }
  
  } catch (FileNotFoundException e) {
      Log.e("Error", "File not found: " + e.getMessage());
  } catch (IOException e) {
      Log.e("Error", "File write failure: " + e.getMessage());
  }
  
  
  private void saveByteArray(FileOutputStream fos, byte[] data) throws IOException {
          long time = System.currentTimeMillis();
          fos.write(data);
          Log.e("saveByteArray: %1dms", "" + (System.currentTimeMillis() - time));
      }
  
  private void saveByteArrayWithOrientation(FileOutputStream fos, byte[] data, int orientation) {
  
          long totalTime = System.currentTimeMillis();
          long time = System.currentTimeMillis();
  
          Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
          Log.e("decodeByteArray: %1dms", "" + (System.currentTimeMillis() - time));
  
          time = System.currentTimeMillis();
          if (orientation != 0 &amp;&amp; bitmap.getWidth() &gt; bitmap.getHeight()) {
              Matrix matrix = new Matrix();
              matrix.postRotate(orientation);
  
              int newWidth;
              int newHeight;
  
              if (bitmap.getWidth() &gt; bitmap.getHeight()) {
                  newHeight = Helper.BITMAP_HEIGHT;
                  newWidth = Helper.BITMAP_HEIGHT * bitmap.getWidth() / bitmap.getHeight();
              } else {
                  newWidth = Helper.BITMAP_HEIGHT;
                  newHeight = Helper.BITMAP_HEIGHT * bitmap.getHeight() / bitmap.getWidth();
              }
  
              bitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);
              bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
          }
          time = System.currentTimeMillis();
          bitmap.compress(Bitmap.CompressFormat.JPEG, Helper.COMPRESS_QUALITY, fos);
          Log.d("compress: %1dms", "" + (System.currentTimeMillis() - time));
          Log.d("bitmap height ", "" + bitmap.getHeight());
          Log.d("bitmap witdh ", "" + bitmap.getWidth());
  
          bitmap.recycle();
  
          Log.d("saveByte: %1dms", "" + (System.currentTimeMillis() - totalTime));
      }
  
  public byte[] getBytesFromBitmap(Bitmap bitmap) {
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.JPEG, Helper.COMPRESS_QUALITY, stream);
          return stream.toByteArray();
      }
  </code></pre>
  
  <p><strong>Here is the output after resizing the image</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/3Vhdk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Vhdk.jpg" alt="image after resizing"></a></p>
  
  <p><strong>But i want the out put like this</strong></p>
  
  <p><a href="https://i.stack.imgur.com/DPW6l.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DPW6l.jpg" alt="enter image description here"></a></p>
  
  <p>Please help and thank for help in advance. </p>