code: private byte[] convert(Bitmap bitmap, String format) {
          final int width = bitmap.getWidth();
          final int height = bitmap.getHeight();
  
          DataBuffer buffer = new DataBufferByte(bitmap.getPixels(), bitmap.getLength());
          WritableRaster writableRaster = Raster.createPackedRaster(buffer, width, height, width, MASKS, null);
          BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          bufferedImage.setData(writableRaster);
  
          try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
              ImageIO.write(bufferedImage, format, outputStream);
              outputStream.close();
              return outputStream.toByteArray();
          } catch (IOException e) {
              throw new RuntimeException(e);
          }
      }
docs: Converts the given <code>Bitmap</code> to the specified image format and returns it as byte array.
  
  @param bitmap the given bitmap, not null
  @param format the given target image format, not null
  @return the converted data in byte array format, not null