Java Code Examples for com.facebook.imagepipeline.image.CloseableStaticBitmap#getUnderlyingBitmap()

The following examples show how to use com.facebook.imagepipeline.image.CloseableStaticBitmap#getUnderlyingBitmap() . 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: OverlayMarker.java    From react-native-baidu-map with MIT License 6 votes vote down vote up
@Override
public void onFinalImageSet(String id, final ImageInfo imageInfo, Animatable animatable) {
    Log.i("onFinalImageSet", id);
    CloseableReference<CloseableImage> imageReference = null;
    try {
        imageReference = dataSource.getResult();
        if (imageReference != null) {
            CloseableImage image = imageReference.get();
            if (image != null && image instanceof CloseableStaticBitmap) {
                CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
                Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
                if (bitmap != null) {
                    bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
                    iconBitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                    BITMAP_DESCRIPTOR_MAP.put(iconInfo.getUri(), iconBitmapDescriptor);
                }
            }
        }
    } finally {
        dataSource.close();
        if (imageReference != null) {
            CloseableReference.closeSafely(imageReference);
        }
        loadingImage = false;
    }
}
 
Example 2
Source File: PostprocessorProducer.java    From fresco with MIT License 6 votes vote down vote up
private CloseableReference<CloseableImage> postprocessInternal(CloseableImage sourceImage) {
  CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) sourceImage;
  Bitmap sourceBitmap = staticBitmap.getUnderlyingBitmap();
  CloseableReference<Bitmap> bitmapRef = mPostprocessor.process(sourceBitmap, mBitmapFactory);
  int rotationAngle = staticBitmap.getRotationAngle();
  int exifOrientation = staticBitmap.getExifOrientation();
  try {
    CloseableStaticBitmap closeableStaticBitmap =
        new CloseableStaticBitmap(
            bitmapRef, sourceImage.getQualityInfo(), rotationAngle, exifOrientation);
    closeableStaticBitmap.setImageExtras(staticBitmap.getExtras());
    return CloseableReference.<CloseableImage>of(closeableStaticBitmap);
  } finally {
    CloseableReference.closeSafely(bitmapRef);
  }
}
 
Example 3
Source File: AMapMarker.java    From react-native-amap with MIT License 5 votes vote down vote up
@Override
public void onFinalImageSet(
        String id,
        @Nullable final ImageInfo imageInfo,
        @Nullable Animatable animatable) {
    CloseableReference<CloseableImage> imageReference = null;
    try {
        imageReference = dataSource.getResult();
        if (imageReference != null) {
            CloseableImage image = imageReference.get();
            if (image != null && image instanceof CloseableStaticBitmap) {
                CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image;
                Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap();
                if (bitmap != null) {
                    bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
                    iconBitmap = bitmap;
                    iconBitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
                }
            }
        }
    } finally {
        dataSource.close();
        if (imageReference != null) {
            CloseableReference.closeSafely(imageReference);
        }
    }
    update();
}
 
Example 4
Source File: PipelineDraweeController.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Drawable createDrawable(CloseableReference<CloseableImage> image) {
  Preconditions.checkState(CloseableReference.isValid(image));
  CloseableImage closeableImage = image.get();
  if (closeableImage instanceof CloseableStaticBitmap) {
    CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage;
    return new BitmapDrawable(mResources, closeableStaticBitmap.getUnderlyingBitmap());
  } else if (closeableImage instanceof CloseableAnimatedImage) {
    return mAnimatedDrawableFactory.create(
        ((CloseableAnimatedImage) closeableImage).getImageResult());
  } else {
    throw new UnsupportedOperationException("Unrecognized image class: " + closeableImage);
  }
}
 
Example 5
Source File: DefaultDrawableFactory.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Nullable
public Drawable createDrawable(CloseableImage closeableImage) {
  try {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.beginSection("DefaultDrawableFactory#createDrawable");
    }
    if (closeableImage instanceof CloseableStaticBitmap) {
      CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage;
      Drawable bitmapDrawable =
          new BitmapDrawable(mResources, closeableStaticBitmap.getUnderlyingBitmap());
      if (!hasTransformableRotationAngle(closeableStaticBitmap)
          && !hasTransformableExifOrientation(closeableStaticBitmap)) {
        // Return the bitmap drawable directly as there's nothing to transform in it
        return bitmapDrawable;
      } else {
        return new OrientedDrawable(
            bitmapDrawable,
            closeableStaticBitmap.getRotationAngle(),
            closeableStaticBitmap.getExifOrientation());
      }
    } else if (mAnimatedDrawableFactory != null
        && mAnimatedDrawableFactory.supportsImageType(closeableImage)) {
      return mAnimatedDrawableFactory.createDrawable(closeableImage);
    }
    return null;
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example 6
Source File: BitmapPrepareProducer.java    From fresco with MIT License 5 votes vote down vote up
private void internalPrepareBitmap(CloseableReference<CloseableImage> newResult) {
  if (newResult == null || !newResult.isValid()) {
    return;
  }

  final CloseableImage closeableImage = newResult.get();
  if (closeableImage == null || closeableImage.isClosed()) {
    return;
  }

  if (closeableImage instanceof CloseableStaticBitmap) {
    final CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) closeableImage;
    final Bitmap bitmap = staticBitmap.getUnderlyingBitmap();
    if (bitmap == null) {
      return;
    }

    final int bitmapByteCount = bitmap.getRowBytes() * bitmap.getHeight();
    if (bitmapByteCount < mMinBitmapSizeBytes) {
      return;
    }
    if (bitmapByteCount > mMaxBitmapSizeBytes) {
      return;
    }

    bitmap.prepareToDraw();
  }
}