com.facebook.imagepipeline.animated.base.AnimatedImageFrame Java Examples

The following examples show how to use com.facebook.imagepipeline.animated.base.AnimatedImageFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimatedDrawableBackendImpl.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
private void renderImageSupportsScaling(Canvas canvas, AnimatedImageFrame frame) {
  double xScale = (double) mRenderedBounds.width() / (double) mAnimatedImage.getWidth();
  double yScale = (double) mRenderedBounds.height() / (double) mAnimatedImage.getHeight();

  int frameWidth = (int) Math.round(frame.getWidth() * xScale);
  int frameHeight = (int) Math.round(frame.getHeight() * yScale);
  int xOffset = (int) (frame.getXOffset() * xScale);
  int yOffset = (int) (frame.getYOffset() * yScale);

  synchronized (this) {
    if (mTempBitmap == null) {
      mTempBitmap = Bitmap.createBitmap(
          mRenderedBounds.width(),
          mRenderedBounds.height(),
          Bitmap.Config.ARGB_8888);
    }
    mTempBitmap.eraseColor(Color.TRANSPARENT);
    frame.renderFrame(frameWidth, frameHeight, mTempBitmap);
    canvas.drawBitmap(mTempBitmap, xOffset, yOffset, null);
  }
}
 
Example #2
Source File: AnimatedDrawableBackendImpl.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public void renderImageDoesNotSupportScaling(Canvas canvas, AnimatedImageFrame frame) {
  int frameWidth = frame.getWidth();
  int frameHeight = frame.getHeight();
  int xOffset = frame.getXOffset();
  int yOffset = frame.getYOffset();
  synchronized (this) {
    if (mTempBitmap == null) {
      mTempBitmap = Bitmap.createBitmap(
          mAnimatedImage.getWidth(),
          mAnimatedImage.getHeight(),
          Bitmap.Config.ARGB_8888);
    }
    mTempBitmap.eraseColor(Color.TRANSPARENT);
    frame.renderFrame(frameWidth, frameHeight, mTempBitmap);

    float xScale = (float) mRenderedBounds.width() / (float) mAnimatedImage.getWidth();
    float yScale = (float) mRenderedBounds.height() / (float) mAnimatedImage.getHeight();
    canvas.save();
    canvas.scale(xScale, yScale);
    canvas.translate(xOffset, yOffset);
    canvas.drawBitmap(mTempBitmap, 0, 0, null);
    canvas.restore();
  }
}
 
Example #3
Source File: AnimatedDrawableBackendImpl.java    From fresco with MIT License 6 votes vote down vote up
private void renderImageSupportsScaling(Canvas canvas, AnimatedImageFrame frame) {
  double xScale = (double) mRenderedBounds.width() / (double) mAnimatedImage.getWidth();
  double yScale = (double) mRenderedBounds.height() / (double) mAnimatedImage.getHeight();

  int frameWidth = (int) Math.round(frame.getWidth() * xScale);
  int frameHeight = (int) Math.round(frame.getHeight() * yScale);
  int xOffset = (int) (frame.getXOffset() * xScale);
  int yOffset = (int) (frame.getYOffset() * yScale);

  synchronized (this) {
    int renderedWidth = mRenderedBounds.width();
    int renderedHeight = mRenderedBounds.height();
    // Update the temp bitmap to be >= rendered dimensions
    prepareTempBitmapForThisSize(renderedWidth, renderedHeight);
    frame.renderFrame(frameWidth, frameHeight, mTempBitmap);
    // Temporary bitmap can be bigger than frame, so we should draw only rendered area of bitmap
    mRenderSrcRect.set(0, 0, renderedWidth, renderedHeight);
    mRenderDstRect.set(xOffset, yOffset, xOffset + renderedWidth, yOffset + renderedHeight);

    canvas.drawBitmap(mTempBitmap, mRenderSrcRect, mRenderDstRect, null);
  }
}
 
Example #4
Source File: AnimatedDrawableBackendImpl.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void renderFrame(int frameNumber, Canvas canvas) {
  AnimatedImageFrame frame  = mAnimatedImage.getFrame(frameNumber);
  try {
    if (mAnimatedImage.doesRenderSupportScaling()) {
      renderImageSupportsScaling(canvas, frame);
    } else {
      renderImageDoesNotSupportScaling(canvas, frame);
    }
  } finally {
    frame.dispose();
  }
}
 
Example #5
Source File: AnimatedDrawableBackendImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void renderFrame(int frameNumber, Canvas canvas) {
  AnimatedImageFrame frame = mAnimatedImage.getFrame(frameNumber);
  try {
    if (mAnimatedImage.doesRenderSupportScaling()) {
      renderImageSupportsScaling(canvas, frame);
    } else {
      renderImageDoesNotSupportScaling(canvas, frame);
    }
  } finally {
    frame.dispose();
  }
}
 
Example #6
Source File: AnimatedDrawableBackendImpl.java    From fresco with MIT License 5 votes vote down vote up
private void renderImageDoesNotSupportScaling(Canvas canvas, AnimatedImageFrame frame) {
  int frameWidth, frameHeight, xOffset, yOffset;
  if (mDownscaleFrameToDrawableDimensions) {
    final int fittedWidth = Math.min(frame.getWidth(), canvas.getWidth());
    final int fittedHeight = Math.min(frame.getHeight(), canvas.getHeight());

    final float scaleX = (float) frame.getWidth() / (float) fittedWidth;
    final float scaleY = (float) frame.getHeight() / (float) fittedHeight;
    final float scale = Math.max(scaleX, scaleY);

    frameWidth = (int) (frame.getWidth() / scale);
    frameHeight = (int) (frame.getHeight() / scale);
    xOffset = (int) (frame.getXOffset() / scale);
    yOffset = (int) (frame.getYOffset() / scale);
  } else {
    frameWidth = frame.getWidth();
    frameHeight = frame.getHeight();
    xOffset = frame.getXOffset();
    yOffset = frame.getYOffset();
  }

  synchronized (this) {
    prepareTempBitmapForThisSize(frameWidth, frameHeight);
    frame.renderFrame(frameWidth, frameHeight, mTempBitmap);

    canvas.save();
    canvas.translate(xOffset, yOffset);
    canvas.drawBitmap(mTempBitmap, 0, 0, null);
    canvas.restore();
  }
}
 
Example #7
Source File: MovieAnimatedImage.java    From fresco with MIT License 4 votes vote down vote up
@Override
public AnimatedImageFrame getFrame(int frameNumber) {
  return mFrames[frameNumber];
}