Java Code Examples for com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory#createBitmap()

The following examples show how to use com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory#createBitmap() . 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: GeneratorPostProcessor.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(
  Bitmap src,
  PlatformBitmapFactory bitmapFactory
) {
  final CloseableReference<Bitmap> bitmapRef = bitmapFactory
    .createBitmap(mWidth, mHeight, MainReactPackageWithFrescoCache.bitmapsConfig());

  try {
    final Bitmap dst = bitmapRef.get();
    final Canvas canvas = new Canvas(dst);
    final Paint paint = new Paint();

    processGenerated(paint, canvas);

    return CloseableReference.cloneOrNull(bitmapRef);
  } finally {
    CloseableReference.closeSafely(bitmapRef);
  }
}
 
Example 2
Source File: RenderscriptGeneratorPostProcessor.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(
  Bitmap src,
  PlatformBitmapFactory bitmapFactory
) {
  final CloseableReference<Bitmap> bitmapRef = bitmapFactory
    .createBitmap(mWidth, mHeight, MainReactPackageWithFrescoCache.bitmapsConfig());

  try {
    final Bitmap dst = bitmapRef.get();

    processGeneratorRenderscript(dst);

    return CloseableReference.cloneOrNull(bitmapRef);
  } finally {
    CloseableReference.closeSafely(bitmapRef);
  }
}
 
Example 3
Source File: ReScalePostprocessor.java    From WindowImageView with MIT License 6 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
    float scale = 1.0f * width / sourceBitmap.getWidth();
    Log.e("ReScalePostprocessor", "scale:" + scale);

    scaledWidth = (int) (sourceBitmap.getWidth() * scale);
    scaledHeight = (int) (sourceBitmap.getHeight() * scale);

    listener.onProcessFinished(scaledWidth, scaledHeight);

    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);
    Bitmap bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);
    CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(bitmap);
    try {
        return CloseableReference.cloneOrNull(bitmapRef);
    } finally {
        CloseableReference.closeSafely(bitmapRef);
    }
}
 
Example 4
Source File: ScalingBlurPostprocessor.java    From fresco with MIT License 6 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(
    Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
  final CloseableReference<Bitmap> bitmapRef =
      bitmapFactory.createBitmap(
          sourceBitmap.getWidth() / mScaleRatio, sourceBitmap.getHeight() / mScaleRatio);

  try {
    final Bitmap destBitmap = bitmapRef.get();
    final Canvas canvas = new Canvas(destBitmap);

    canvas.drawBitmap(
        sourceBitmap,
        null,
        new Rect(0, 0, destBitmap.getWidth(), destBitmap.getHeight()),
        mPaint);

    NativeBlurFilter.iterativeBoxBlur(
        destBitmap, mIterations, Math.max(1, mBlurRadius / mScaleRatio));
    return CloseableReference.cloneOrNull(bitmapRef);
  } finally {
    CloseableReference.closeSafely(bitmapRef);
  }
}
 
Example 5
Source File: PorterDuffXfermodePostProcessor.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Override
protected CloseableReference<Bitmap> processComposition(
  Bitmap dstImage,
  Bitmap srcImage,
  PlatformBitmapFactory bitmapFactory
) {
  final CloseableReference<Bitmap> outRef = bitmapFactory.createBitmap(
    canvasExtent(dstImage.getWidth(), srcImage.getWidth(), mWidth),
    canvasExtent(dstImage.getHeight(), srcImage.getHeight(), mHeight)
  );

  try {
    final Canvas canvas = new Canvas(outRef.get());
    final int flags = Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG;
    final Paint paint = new Paint(flags);

    if (mSwapImages) {
      drawSrc(canvas, srcImage, paint);

    } else {
      drawDst(canvas, dstImage, paint);
    }

    paint.setXfermode(new PorterDuffXfermode(mMode));

    if (mSwapImages) {
      drawDst(canvas, dstImage, paint);

    } else {
      drawSrc(canvas, srcImage, paint);
    }

    return CloseableReference.cloneOrNull(outRef);
  } finally {
    CloseableReference.closeSafely(outRef);
  }
}
 
Example 6
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(Bitmap source, PlatformBitmapFactory bitmapFactory) {
  final Rect destRect = new Rect(0, 0, getWidth(), getHeight());

  mScaleType.getTransform(
    sTileMatrix,
    destRect,
    source.getWidth(),
    source.getHeight(),
    0.0f,
    0.0f);

  Paint paint = new Paint();
  paint.setAntiAlias(true);
  Shader shader = new BitmapShader(source, mTileMode, mTileMode);
  shader.setLocalMatrix(sTileMatrix);
  paint.setShader(shader);

  CloseableReference<Bitmap> output = bitmapFactory.createBitmap(getWidth(), getHeight());
  try {
    Canvas canvas = new Canvas(output.get());
    canvas.drawRect(destRect, paint);
    return output.clone();
  } finally {
    CloseableReference.closeSafely(output);
  }
}
 
Example 7
Source File: RenderscriptCompositionPostProcessor.java    From react-native-image-filter-kit with MIT License 4 votes vote down vote up
@Override
protected CloseableReference<Bitmap> processComposition(
  Bitmap dstImage,
  Bitmap srcImage,
  PlatformBitmapFactory bitmapFactory
) {
  final int width = canvasExtent(dstImage.getWidth(), srcImage.getWidth(), mWidth);
  final int height = canvasExtent(dstImage.getHeight(), srcImage.getHeight(), mHeight);

  final CloseableReference<Bitmap> tmpDstRef = bitmapFactory.createBitmap(width, height);
  final CloseableReference<Bitmap> tmpSrcRef = bitmapFactory.createBitmap(width, height);
  final CloseableReference<Bitmap> outRef = bitmapFactory.createBitmap(width, height);

  try {
    final Bitmap out = outRef.get();
    final Bitmap tmpDst = tmpDstRef.get();
    final Bitmap tmpSrc = tmpSrcRef.get();

    final Canvas dstCanvas = new Canvas(tmpDst);
    final Canvas srcCanvas = new Canvas(tmpSrc);
    final int flags = Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG;
    final Paint paint = new Paint(flags);

    dstCanvas.drawBitmap(
      dstImage,
      bitmapTransform(width, height, dstImage.getWidth(), dstImage.getHeight(), mDstTransform),
      paint
    );

    srcCanvas.drawBitmap(
      srcImage,
      bitmapTransform(width, height, srcImage.getWidth(), srcImage.getHeight(), mSrcTransform),
      paint
    );

    processRenderscriptComposition(
      mSwapImages ? tmpSrc : tmpDst,
      mSwapImages ? tmpDst : tmpSrc,
      out
    );

    return CloseableReference.cloneOrNull(outRef);
  } finally {
    CloseableReference.closeSafely(tmpDstRef);
    CloseableReference.closeSafely(tmpSrcRef);
    CloseableReference.closeSafely(outRef);
  }
}