Allows you to modify or clear a bitmap that was loaded for an image either automatically
through {@link #setImagesAssetsFolder(String)} or with an {@link ImageAssetDelegate}.

@return the previous Bitmap or null.
970850
@Nullable
  public Bitmap updateBitmap(String id, @Nullable Bitmap bitmap) {
    ImageAssetManager bm = getImageAssetManager();
    if (bm == null) {
      Log.w(L.TAG, "Cannot update bitmap. Most likely the drawable is not added to a View " +
          "which prevents Lottie from getting a Context.");
      return null;
    }
    Bitmap ret = bm.updateBitmap(id, bitmap);
    invalidateSelf();
    return ret;
  }
1331132
private Bitmap getBitmapOfView(final View view){
		view.destroyDrawingCache();
		view.buildDrawingCache(false);
		Bitmap orig = view.getDrawingCache();
		Bitmap.Config config = null;

		if(orig == null) {
			return null;
		}

		config = orig.getConfig();

		if(config == null) {
			config = Bitmap.Config.ARGB_8888;
		}
		Bitmap b = orig.copy(config, false);
		orig.recycle();
		view.destroyDrawingCache();
		return b; 
	}
691442
@Override
	public final Bitmap get(String key) {
		if (key == null) {
			throw new NullPointerException("key == null");
		}

		synchronized (this) {
			return map.get(key);
		}
	}
1268614
public String getBitmap()
    {
        if (m_recTarget != null)
        {
            Record recTarget = null;
            if (m_recTarget.getBaseRecord().getTable().getCurrentTable() != null)
                recTarget = m_recTarget.getBaseRecord().getTable().getCurrentTable().getRecord();
            if (recTarget != null)
                return recTarget.getBitmap();   // Bitmap for this table
        }
        return super.getBitmap(); // Default value
    }
1353720
protected @Nullable HtmlElement<?> getImageElement(@NotNull Media media) {
    Image img = null;

    MediaArgs mediaArgs = media.getMediaRequest().getMediaArgs();
    Asset asset = media.getAsset();
    Rendition rendition = media.getRendition();

    String url = null;
    if (rendition != null) {
      url = rendition.getUrl();
    }

    if (url != null) {
      img = new Image(url);

      // Alternative text
      String altText = null;
      if (asset != null) {
        altText = asset.getAltText();
      }
      if (StringUtils.isNotEmpty(altText)) {
        img.setAlt(altText);
      }

      // set width/height
      if (rendition != null && mediaArgs.getImageSizes() == null && mediaArgs.getPictureSources() == null) {
        long height = rendition.getHeight();
        if (height > 0) {
          img.setHeight(height);
        }
        long width = rendition.getWidth();
        if (width > 0) {
          img.setWidth(width);
        }
      }

      // set image sizes/srcset
      ImageSizes imageSizes = mediaArgs.getImageSizes();
      if (imageSizes != null) {
        MediaFormat primaryMediaFormat = getFirstMediaFormatWithRatio(media);
        if (primaryMediaFormat != null) {
          String srcSet = getSrcSetRenditions(media, primaryMediaFormat, imageSizes.getWidths());
          if (srcSet != null) {
            img.setSrcSet(srcSet);
            img.setSizes(imageSizes.getSizes());
          }
        }
      }

    }

    // set additional attributes
    setAdditionalAttributes(img, media);

    return img;
  }
1095007
private String compressImage(String imagePath, File destDirectory) {

        Bitmap scaledBitmap = null;

        BitmapFactory.Options options = new BitmapFactory.Options();

//      by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If
//      you try the use the bitmap here, you will get null.
        options.inJustDecodeBounds = true;
        Bitmap bmp = BitmapFactory.decodeFile(imagePath, options);

        int actualHeight = options.outHeight;
        int actualWidth = options.outWidth;

//      max Height and width values of the compressed image is taken as 816x612

        float maxHeight = 816.0f;
        float maxWidth = 612.0f;
        float imgRatio = actualWidth / actualHeight;
        float maxRatio = maxWidth / maxHeight;

//      width and height values are set maintaining the aspect ratio of the image

        if (actualHeight > maxHeight || actualWidth > maxWidth) {
            if (imgRatio < maxRatio) {
                imgRatio = maxHeight / actualHeight;
                actualWidth = (int) (imgRatio * actualWidth);
                actualHeight = (int) maxHeight;
            } else if (imgRatio > maxRatio) {
                imgRatio = maxWidth / actualWidth;
                actualHeight = (int) (imgRatio * actualHeight);
                actualWidth = (int) maxWidth;
            } else {
                actualHeight = (int) maxHeight;
                actualWidth = (int) maxWidth;

            }
        }

//      setting inSampleSize value allows to load a scaled down version of the original image

        options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);

//      inJustDecodeBounds set to false to load the actual bitmap
        options.inJustDecodeBounds = false;

//      this options allow android to claim the bitmap memory if it runs low on memory
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inTempStorage = new byte[16 * 1024];

        try {
//          load the bitmap from its path
            bmp = BitmapFactory.decodeFile(imagePath, options);
        } catch (OutOfMemoryError exception) {
            exception.printStackTrace();

        }
        try {
            scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError exception) {
            exception.printStackTrace();
        }

        float ratioX = actualWidth / (float) options.outWidth;
        float ratioY = actualHeight / (float) options.outHeight;
        float middleX = actualWidth / 2.0f;
        float middleY = actualHeight / 2.0f;

        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);

        Canvas canvas = new Canvas(scaledBitmap);
        canvas.setMatrix(scaleMatrix);
        canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));

//      check the rotation of the image and display it properly
        ExifInterface exif;
        try {
            exif = new ExifInterface(imagePath);

            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION, 0);
            Log.d("EXIF", "Exif: " + orientation);
            Matrix matrix = new Matrix();
            if (orientation == 6) {
                matrix.postRotate(90);
                Log.d("EXIF", "Exif: " + orientation);
            } else if (orientation == 3) {
                matrix.postRotate(180);
                Log.d("EXIF", "Exif: " + orientation);
            } else if (orientation == 8) {
                matrix.postRotate(270);
                Log.d("EXIF", "Exif: " + orientation);
            }
            scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0,
                    scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix,
                    true);
        } catch (IOException e) {
            e.printStackTrace();
        }

        FileOutputStream out = null;
        String resultFilePath = getFilename(imagePath, destDirectory);
        try {
            out = new FileOutputStream(resultFilePath);

            //  write the compressed bitmap at the destination specified by filename.
            scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return resultFilePath;

    }
21133
@Deprecated
  public static int resetBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end) {
    int cardbefore = cardinalityInBitmapWordRange(bitmap, start, end);
    resetBitmapRange(bitmap, start,end);
    int cardafter = cardinalityInBitmapWordRange(bitmap, start, end);
    return cardafter - cardbefore;
  }
8337
@Override
  @Deprecated
  public void setImageBitmap(Bitmap bm) {
    init(getContext());
    mDraweeHolder.setController(null);
    super.setImageBitmap(bm);
  }
1172858
public static Bitmap loadBitmap(Uri uri, Context context) throws ImageLoadException {
        return loadBitmap(new UriSource(uri, context));
    }
851763
Image fillImage() {
    if (fillImage == null) {
      CanvasImage image = platform.graphics().createImage(1, 1);
      image.canvas().setFillColor(0xFFFFFFFF).fillRect(0, 0, image.width(), image.height());
      fillImage = image;
    }
    return fillImage;
  }
658782
Bitmap getBitmap(int position) {
    return bitmaps[position] != null ? bitmaps[position].get() : null;
  }
1000344
public BufferedImage getNewImageInstance() {
        BufferedImage buf = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
        buf.setData(image.getData());
        return buf;
    }
324958
public static MutableRoaringBitmap priorityqueue_or(ImmutableRoaringBitmap... bitmaps) {
    if (bitmaps.length == 0) {
      return new MutableRoaringBitmap();
    } else if (bitmaps.length == 1) {
      return bitmaps[0].toMutableRoaringBitmap();
    }
    // we buffer the call to getLongSizeInBytes(), hence the code complexity
    final ImmutableRoaringBitmap[] buffer = Arrays.copyOf(bitmaps, bitmaps.length);
    final int[] sizes = new int[buffer.length];
    final boolean[] istmp = new boolean[buffer.length];
    for (int k = 0; k < sizes.length; ++k) {
      sizes[k] = buffer[k].serializedSizeInBytes();
    }
    PriorityQueue<Integer> pq = new PriorityQueue<>(128, new Comparator<Integer>() {
      @Override
      public int compare(Integer a, Integer b) {
        return sizes[a] - sizes[b];
      }
    });
    for (int k = 0; k < sizes.length; ++k) {
      pq.add(k);
    }
    while (pq.size() > 1) {
      Integer x1 = pq.poll();
      Integer x2 = pq.poll();
      if (istmp[x1] && istmp[x2]) {
        buffer[x1] = MutableRoaringBitmap.lazyorfromlazyinputs((MutableRoaringBitmap) buffer[x1],
            (MutableRoaringBitmap) buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        pq.add(x1);
      } else if (istmp[x2]) {
        ((MutableRoaringBitmap) buffer[x2]).lazyor(buffer[x1]);
        sizes[x2] = buffer[x2].serializedSizeInBytes();
        pq.add(x2);
      } else if (istmp[x1]) {
        ((MutableRoaringBitmap) buffer[x1]).lazyor(buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        pq.add(x1);
      } else {
        buffer[x1] = ImmutableRoaringBitmap.lazyor(buffer[x1], buffer[x2]);
        sizes[x1] = buffer[x1].serializedSizeInBytes();
        istmp[x1] = true;
        pq.add(x1);
      }
    }
    MutableRoaringBitmap answer = (MutableRoaringBitmap) buffer[pq.poll()];
    answer.repairAfterLazy();
    return answer;
  }
551050
private Image loadImage(final String resourceName, final boolean skipImagesFolder) {
        Image image = null;

        final List<String> imagePaths = skipImagesFolder ? Collections.singletonList("") : ResourceParameters.IMAGE_FOLDER.get();
        for (int i = 0; i < imagePaths.size() && image == null; i++) {

            String imagePath = imagePaths.get(i);
            if (!imagePath.isEmpty()) {
                imagePath += Resources.PATH_SEP;
            }
            final InputStream imageInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(imagePath + resourceName);
            if (imageInputStream != null) {
                image = new Image(imageInputStream);
            }
        }
        if (image == null) {
            LOGGER.error("Image : {} not found into base folder: {}", resourceName, ResourceParameters.IMAGE_FOLDER.get());
        }
        return image;
    }
1285920
@Override
    protected void destroyBitmap() {
        if (this.bitmap != null) {
            if (removeBitmap(this.hash)) {
                this.bitmap.recycle();
            }
            this.bitmap = null;
        }
    }
491723
synchronized void loadImageIfNecessary(final boolean isInLayoutPass) {
        int width = getWidth();
        int height = getHeight();

        boolean wrapWidth = false, wrapHeight = false;
        if (getLayoutParams() != null) {
            wrapWidth = getLayoutParams().width == LayoutParams.WRAP_CONTENT;
            wrapHeight = getLayoutParams().height == LayoutParams.WRAP_CONTENT;
        }

        // if the view's bounds aren't known yet, and this is not a wrap-content/wrap-content
        // view, hold off on loading the image.
        boolean isFullyWrapContent = wrapWidth && wrapHeight;
        if (width == 0 && height == 0 && !isFullyWrapContent) {
            return;
        }

        // if the URL to be loaded in this view is empty, cancel any old requests and clear the
        // currently loaded image.
        if (TextUtils.isEmpty(url)) {
            if (imageContainer != null) {
                imageContainer.cancelRequest();
                imageContainer = null;
            }
            setDefaultImageOrNull();
            return;
        }

        // if there was an old request in this view, check if it needs to be canceled.
        if (imageContainer != null && imageContainer.getRequestUrl() != null) {
            if (imageContainer.getRequestUrl().equals(url)) {
                // if the request is from the same URL, return.
                return;
            } else {
                // if there is a pre-existing request, cancel it if it's fetching a different URL.
                imageContainer.cancelRequest();
                setDefaultImageOrNull();
            }
        }

        // Calculate the max image width / height to use while ignoring WRAP_CONTENT dimens.
        int maxWidth = wrapWidth ? 0 : width;
        int maxHeight = wrapHeight ? 0 : height;

        // The pre-existing content of this view didn't match the current URL. Load the new image
        // from the network.
        ImageContainer newContainer = imageLoader.get(url,
                new ImageListener() {
                    @Override
                    public void onError(JusError error) {
                        if (errorImageId != 0) {
                            setImageResource(errorImageId);
                        }
                    }

                    @Override
                    public void onResponse(final ImageContainer response, boolean isImmediate) {
                        //verify if we expect the same url
                        if (NetworkImageView.this.url == null ||
                                !NetworkImageView.this.url.equals(response.getRequestUrl())) {
                            JusLog.error("NetworkImageView received: " + response.getRequestUrl()
                                    + ", expected: " + NetworkImageView.this.url);
                            return;
                        }

                        // If this was an immediate response that was delivered inside of a layout
                        // pass do not set the image immediately as it will trigger a requestLayout
                        // inside of a layout. Instead, defer setting the image by posting back to
                        // the main threadId.
                        if (isImmediate && isInLayoutPass) {
                            post(new Runnable() {
                                @Override
                                public void run() {
                                    onResponse(response, false);
                                }
                            });
                            return;
                        }

                        if (response.getBitmap() != null && isOk2Draw(response.getBitmap())) {
                            setImageBitmap(response.getBitmap());
                        } else if (defaultImageId != 0) {
                            if (!isImmediate) {
                                JusLog.error("NetworkImageView received null for: " + response
                                        .getRequestUrl());
                            }
                            setImageResource(defaultImageId);
                        }
                    }
                }, maxWidth, maxHeight, tag);

        // update the ImageContainer to be the new bitmap container.
        imageContainer = newContainer;
    }
525887
public boolean runOptimize() {
    boolean hasChanged = false;
    for (BitmapDataProvider lowBitmap : highToBitmap.values()) {
      if (lowBitmap instanceof RoaringBitmap) {
        hasChanged |= ((RoaringBitmap) lowBitmap).runOptimize();
      } else if (lowBitmap instanceof MutableRoaringBitmap) {
        hasChanged |= ((MutableRoaringBitmap) lowBitmap).runOptimize();
      }
    }
    return hasChanged;
  }