com.facebook.imagepipeline.image.CloseableBitmap Java Examples

The following examples show how to use com.facebook.imagepipeline.image.CloseableBitmap. 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: BaseBitmapDataSubscriber.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    return;
  }

  CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
  Bitmap bitmap = null;
  if (closeableImageRef != null &&
      closeableImageRef.get() instanceof CloseableBitmap) {
    bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
  }

  try {
    onNewResultImpl(bitmap);
  } finally {
    CloseableReference.closeSafely(closeableImageRef);
  }
}
 
Example #2
Source File: BaseBitmapDataSubscriber.java    From fresco with MIT License 6 votes vote down vote up
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
  if (!dataSource.isFinished()) {
    return;
  }

  CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
  Bitmap bitmap = null;
  if (closeableImageRef != null && closeableImageRef.get() instanceof CloseableBitmap) {
    bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
  }

  try {
    onNewResultImpl(bitmap);
  } finally {
    CloseableReference.closeSafely(closeableImageRef);
  }
}
 
Example #3
Source File: CompositionPostProcessor.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(
  Bitmap dst,
  PlatformBitmapFactory bitmapFactory
) {
  Bitmap src = ((CloseableBitmap) mSrc.get()).getUnderlyingBitmap();

  return processComposition(dst, src, bitmapFactory);
}
 
Example #4
Source File: TempFileUtils.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
static void writeFile(
  @NonNull final ReactContext context,
  @NonNull final CloseableReference<CloseableImage> ref,
  @NonNull final Functor.Arity1<String> sendUri,
  @NonNull final Functor.Arity1<String> sendError
) {
  CloseableReference<CloseableImage> cloned = ref.clone();

  Task.callInBackground((Callable<Void>) () -> {
    try {
      final File outputFile = createFile(context);
      final FileOutputStream fos = new FileOutputStream(outputFile);
      final Bitmap bitmap = ((CloseableBitmap) cloned.get()).getUnderlyingBitmap();

      bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);

      final String path = Uri.fromFile(outputFile).toString();

      FLog.w(ReactConstants.TAG, "ImageFilterKit: created file " + path);

      Task.call((Callable<Void>) () -> {
        sendUri.call(path);

        return null;
      }, UiThreadImmediateExecutorService.getInstance());

    } catch (Exception e) {
      Task.call((Callable<Void>) () -> {
        sendError.call(e.getMessage());

        return null;
      }, UiThreadImmediateExecutorService.getInstance());

    } finally {
      CloseableReference.closeSafely(cloned);
    }

    return null;
  });
}
 
Example #5
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private void postprocessBitmap(
    CloseableReference<CloseableImage> destinationCloseableImageRef,
    Postprocessor postprocessor) {
  Bitmap destinationBitmap =
      ((CloseableBitmap) destinationCloseableImageRef.get()).getUnderlyingBitmap();
  postprocessor.process(destinationBitmap);
}
 
Example #6
Source File: DecodeProducer.java    From fresco with MIT License 5 votes vote down vote up
private void setImageExtras(EncodedImage encodedImage, CloseableImage image) {
  mProducerContext.setExtra(ProducerContext.ExtraKeys.ENCODED_WIDTH, encodedImage.getWidth());
  mProducerContext.setExtra(ProducerContext.ExtraKeys.ENCODED_HEIGHT, encodedImage.getHeight());
  mProducerContext.setExtra(ProducerContext.ExtraKeys.ENCODED_SIZE, encodedImage.getSize());
  if (image instanceof CloseableBitmap) {
    Bitmap bitmap = ((CloseableBitmap) image).getUnderlyingBitmap();
    Bitmap.Config config = bitmap == null ? null : bitmap.getConfig();
    mProducerContext.setExtra("bitmap_config", String.valueOf(config));
  }
  if (image != null) {
    image.setImageExtras(mProducerContext.getExtras());
  }
}
 
Example #7
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 5 votes vote down vote up
private void storeEntries(
    List<CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage>> entries,
    int i,
    PrintStream writer,
    File directory)
    throws IOException {
  String filename;
  for (CountingMemoryCacheInspector.DumpInfoEntry<CacheKey, CloseableImage> entry : entries) {
    CloseableImage closeableImage = entry.value.get();
    if (closeableImage instanceof CloseableBitmap) {
      CloseableBitmap closeableBitmap = (CloseableBitmap) closeableImage;
      filename = "tmp" + i + ".png";
      writer.println(
          formatStrLocaleSafe("Storing image %d as %s. Key: %s", i, filename, entry.key));
      storeImage(
          closeableBitmap.getUnderlyingBitmap(),
          new File(directory, filename),
          Bitmap.CompressFormat.PNG,
          100);
    } else {
      writer.println(
          formatStrLocaleSafe(
              "Image %d has unrecognized type %s. Key: %s", i, closeableImage, entry.key));
    }
    i++;
  }
}
 
Example #8
Source File: MyBaseBitmapDataSubscriber.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
@Override
public void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
    if (!dataSource.isFinished()) {
        return;
    }

    CloseableReference<CloseableImage> closeableImageRef = dataSource.getResult();
    Bitmap bitmap = null;
    if (closeableImageRef != null &&
            closeableImageRef.get() instanceof CloseableBitmap) {
        bitmap = ((CloseableBitmap) closeableImageRef.get()).getUnderlyingBitmap();
    }


    if(bitmap!=null ){
        if(bitmap.isRecycled()){
            onFail(new Throwable("bitmap.isRecycled"));
        }else {
            onNewResultImpl(bitmap,dataSource);
        }
        return;
    }

    //如果bitmap为空
    Log.e("onNewResultImpl","finalUrl :"+finalUrl);
    File cacheFile  = ImageLoader.getActualLoader().getFileFromDiskCache(finalUrl);
    if(cacheFile ==null){
        onFail(new Throwable("file cache is null:"+finalUrl));
        return;
    }
    //还要判断文件是不是gif格式的
    if (!"gif".equalsIgnoreCase(MyUtil.getRealType(cacheFile))){
        onFail(new Throwable("file cache is not gif:"+finalUrl));
        return;
    }
    Bitmap bitmapGif = GifUtils.getBitmapFromGifFile(cacheFile);//拿到gif第一帧的bitmap
    if(width>0 && height >0) {
        bitmapGif = MyUtil.compressBitmap(bitmapGif, false, width, height);//将bitmap压缩到指定宽高。
    }

    if (bitmapGif != null) {
        onNewResultImpl(bitmapGif,dataSource);
    } else {
        onFail(new Throwable("can not create bitmap from gif file:"+cacheFile.getAbsolutePath()));
    }




   /* try {
        onNewResultImpl(bitmap);
    } finally {
        //CloseableReference.closeSafely(closeableImageRef);
    }*/
}
 
Example #9
Source File: CanViewPagerActivity.java    From CanPhotos with Apache License 2.0 4 votes vote down vote up
private void handleBitmap(CloseableBitmap closeableBitmap, int position) {
    Bitmap bitmap = closeableBitmap.getUnderlyingBitmap();
    map.put(position, bitmap);

}
 
Example #10
Source File: FrescoFrameCache.java    From fresco with MIT License 4 votes vote down vote up
private static int getBitmapSizeBytes(@Nullable CloseableImage image) {
  if (!(image instanceof CloseableBitmap)) {
    return 0;
  }
  return BitmapUtil.getSizeInBytes(((CloseableBitmap) image).getUnderlyingBitmap());
}