Java 类com.bumptech.glide.load.resource.bitmap.BitmapResource 实例源码

项目:GitHub    文件:GifDrawableTransformation.java   
@Override
public Resource<GifDrawable> transform(
    Context context, Resource<GifDrawable> resource, int outWidth, int outHeight) {
  GifDrawable drawable = resource.get();

  // The drawable needs to be initialized with the correct width and height in order for a view
  // displaying it to end up with the right dimensions. Since our transformations may arbitrarily
  // modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the
  // transformation to see what the final transformed dimensions will be so that our drawable can
  // report the correct intrinsic width and height.
  BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
  Bitmap firstFrame = drawable.getFirstFrame();
  Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool);
  Resource<Bitmap> transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight);
  if (!bitmapResource.equals(transformed)) {
    bitmapResource.recycle();
  }
  Bitmap transformedFrame = transformed.get();

  drawable.setFrameTransformation(wrapped, transformedFrame);
  return resource;
}
项目:GitHub    文件:GifDrawableTransformation.java   
@Override
public Resource<GifDrawable> transform(
    Context context, Resource<GifDrawable> resource, int outWidth, int outHeight) {
  GifDrawable drawable = resource.get();

  // The drawable needs to be initialized with the correct width and height in order for a view
  // displaying it to end up with the right dimensions. Since our transformations may arbitrarily
  // modify the dimensions of our GIF, here we create a stand in for a frame and pass it to the
  // transformation to see what the final transformed dimensions will be so that our drawable can
  // report the correct intrinsic width and height.
  BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
  Bitmap firstFrame = drawable.getFirstFrame();
  Resource<Bitmap> bitmapResource = new BitmapResource(firstFrame, bitmapPool);
  Resource<Bitmap> transformed = wrapped.transform(context, bitmapResource, outWidth, outHeight);
  if (!bitmapResource.equals(transformed)) {
    bitmapResource.recycle();
  }
  Bitmap transformedFrame = transformed.get();

  drawable.setFrameTransformation(wrapped, transformedFrame);
  return resource;
}
项目:PeSanKita-android    文件:BitmapUtil.java   
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
    throws BitmapDecodingException
{
  final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model),
                                                   Glide.get(context).getBitmapPool(),
                                                   width, height,
                                                   DecodeFormat.PREFER_RGB_565);

  final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool());
  final Resource<Bitmap> result   = new FitCenter(context).transform(resource, width, height);

  if (result == null) {
    throw new BitmapDecodingException("unable to transform Bitmap");
  }
  return result.get();
}
项目:Nird2    文件:BitmapUtil.java   
private static <T> Bitmap createScaledBitmapInto(Context context, T model,
        int width, int height)
        throws BitmapDecodingException {
    final Bitmap rough = Downsampler.AT_LEAST
            .decode(getInputStreamForModel(context, model),
                    Glide.get(context).getBitmapPool(),
                    width, height, DecodeFormat.PREFER_RGB_565);

    final Resource<Bitmap> resource = BitmapResource
            .obtain(rough, Glide.get(context).getBitmapPool());
    final Resource<Bitmap> result =
            new FitCenter(context).transform(resource, width, height);

    if (result == null) {
        throw new BitmapDecodingException("unable to transform Bitmap");
    }
    return result.get();
}
项目:Nird2    文件:BitmapUtil.java   
private static <T> Bitmap createScaledBitmapInto(Context context, T model,
        int width, int height)
        throws BitmapDecodingException {
    final Bitmap rough = Downsampler.AT_LEAST
            .decode(getInputStreamForModel(context, model),
                    Glide.get(context).getBitmapPool(),
                    width, height, DecodeFormat.PREFER_RGB_565);

    final Resource<Bitmap> resource = BitmapResource
            .obtain(rough, Glide.get(context).getBitmapPool());
    final Resource<Bitmap> result =
            new FitCenter(context).transform(resource, width, height);

    if (result == null) {
        throw new BitmapDecodingException("unable to transform Bitmap");
    }
    return result.get();
}
项目:XinFramework    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint, width, height);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:ColorFilterTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:GrayscaleTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  ColorMatrix saturation = new ColorMatrix();
  saturation.setSaturation(0f);
  Paint paint = new Paint();
  paint.setColorFilter(new ColorMatrixColorFilter(saturation));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:MaskTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (result == null) {
    result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);

  Canvas canvas = new Canvas(result);
  mask.setBounds(0, 0, width, height);
  mask.draw(canvas);
  canvas.drawBitmap(source, 0, 0, sMaskingPaint);

  return BitmapResource.obtain(result, mBitmapPool);
}
项目:Glide-transformations    文件:CropSquareTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  mWidth = (source.getWidth() - size) / 2;
  mHeight = (source.getHeight() - size) / 2;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:GeekZone    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.RGB_565);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:GlidePlus    文件:ImageWrapperResourceDecoder.java   
private ImageWrapper decodeGifWrapper(InputStream bis, int width, int height) throws IOException {
    ImageWrapper result = null;
    Resource<GifDrawable> gifResource = gifDecoder.decode(bis, width, height);
    if (gifResource != null) {
        GifDrawable drawable = gifResource.get();
        // We can more efficiently hold Bitmaps in memory, so for static GIFs, try to return Bitmaps
        // instead. Returning a Bitmap incurs the cost of allocating the GifDrawable as well as the normal
        // Bitmap allocation, but since we can encode the Bitmap out as a JPEG, future decodes will be
        // efficient.
        if (drawable.getNumberOfFrames() > 1) {
            result = new ImageWrapper(null /*bitmapResource*/, gifResource);
        } else {
            Resource<Bitmap> bitmapResource = new BitmapResource(drawable.getCurrentFrame(), bitmapPool);
            result = new ImageWrapper(bitmapResource, null /*gifResource*/);
        }
    }
    return result;
}
项目:Cable-Android    文件:BitmapUtil.java   
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
    throws BitmapDecodingException
{
  final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model),
                                                   Glide.get(context).getBitmapPool(),
                                                   width, height,
                                                   DecodeFormat.PREFER_RGB_565);

  final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool());
  final Resource<Bitmap> result   = new FitCenter(context).transform(resource, width, height);

  if (result == null) {
    throw new BitmapDecodingException("unable to transform Bitmap");
  }
  return result.get();
}
项目:TripBuyer    文件:ImageUtil.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {

    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(source, 0, 0, mMaskingPaint);
    canvas.drawColor(0x44000000);

    return BitmapResource.obtain(result, mBitmapPool);
}
项目:gigigo-imageLoader-library-android    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:aptoide-client-v8    文件:RoundedCornersTransform.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:glide-support    文件:RawFileDecoder.java   
@Override public @Nullable Resource<Bitmap> decode(File file, int w, int h, Options options) throws IOException {
    ByteBuffer buffer = ByteBuffer.allocate(w * h * 4);
    FileInputStream stream = new FileInputStream(file);
    try {
        stream.getChannel().read(buffer);
    } finally {
        stream.close();
    }
    Bitmap result = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    try {
        buffer.rewind();
        result.copyPixelsFromBuffer(buffer);
        return BitmapResource.obtain(result, pool);
    } catch (RuntimeException ex) {
        result.recycle();
        throw ex;
    }
}
项目:BaseLibrary    文件:ColorFilterTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:BaseLibrary    文件:GrayscaleTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  ColorMatrix saturation = new ColorMatrix();
  saturation.setSaturation(0f);
  Paint paint = new Paint();
  paint.setColorFilter(new ColorMatrixColorFilter(saturation));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:BaseLibrary    文件:MaskTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (result == null) {
    result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);

  Canvas canvas = new Canvas(result);
  mask.setBounds(0, 0, width, height);
  mask.draw(canvas);
  canvas.drawBitmap(source, 0, 0, sMaskingPaint);

  return BitmapResource.obtain(result, mBitmapPool);
}
项目:BaseLibrary    文件:CropSquareTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  mWidth = (source.getWidth() - size) / 2;
  mHeight = (source.getHeight() - size) / 2;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:BaseLibrary    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
  drawRoundRect(canvas, paint, width, height);
  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:WhisperTweetNothings    文件:RoundedCornersTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint, width, height);
    return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:glide-transformations    文件:BitmapTransformation.java   
@Override
public final Resource<Bitmap> transform(Context context, Resource<Bitmap> resource, int outWidth,
    int outHeight) {
  if (!Util.isValidDimensions(outWidth, outHeight)) {
    throw new IllegalArgumentException(
        "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
            + " less than or equal to zero and not Target.SIZE_ORIGINAL");
  }
  BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
  Bitmap toTransform = resource.get();
  int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
  int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
  Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);

  final Resource<Bitmap> result;
  if (toTransform.equals(transformed)) {
    result = resource;
  } else {
    result = BitmapResource.obtain(transformed, bitmapPool);
  }
  return result;
}
项目:Silence    文件:BitmapUtil.java   
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
    throws BitmapDecodingException
{
  final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model),
                                                   Glide.get(context).getBitmapPool(),
                                                   width, height,
                                                   DecodeFormat.PREFER_RGB_565);

  final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool());
  final Resource<Bitmap> result   = new FitCenter(context).transform(resource, width, height);

  if (result == null) {
    throw new BitmapDecodingException("unable to transform Bitmap");
  }
  return result.get();
}
项目:mage-android    文件:AttachmentVideoDecoder.java   
private BitmapResource decodeWithUrl(String url) {
    String token = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(mil.nga.giat.mage.sdk.R.string.tokenKey), null);

    try {
        Map<String, String> headers = new HashMap<>();
        headers.put("authorization", "Bearer " + token);
        mediaMetadataRetriever.setDataSource(url, headers);
        Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(100);

        return new BitmapResource(bitmap, bitmapPool);
    } finally {
        if (mediaMetadataRetriever != null) {
            mediaMetadataRetriever.release();
        }
    }
}
项目:q-mail    文件:ContactPictureLoader.java   
@Override
public Resource<Bitmap> decode(FallbackGlideParams source, int width, int height) throws IOException {
    BitmapPool pool = Glide.get(context).getBitmapPool();
    Bitmap bitmap = pool.getDirty(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(mPictureSizeInPx, mPictureSizeInPx, Bitmap.Config.ARGB_8888);
    }
    drawTextAndBgColorOnBitmap(bitmap, source);
    return BitmapResource.obtain(bitmap, pool);
}
项目:GitHub    文件:BitmapPreFillRunner.java   
/**
 * Attempts to allocate {@link android.graphics.Bitmap}s and returns {@code true} if there are
 * more {@link android.graphics.Bitmap}s to allocate and {@code false} otherwise.
 */
private boolean allocate() {
  long start = clock.now();
  while (!toPrefill.isEmpty() && !isGcDetected(start)) {
    PreFillType toAllocate = toPrefill.remove();
    final Bitmap bitmap;
    if (!seenTypes.contains(toAllocate)) {
      seenTypes.add(toAllocate);
      bitmap = bitmapPool.getDirty(toAllocate.getWidth(), toAllocate.getHeight(),
          toAllocate.getConfig());
    } else {
      bitmap = Bitmap.createBitmap(toAllocate.getWidth(), toAllocate.getHeight(),
          toAllocate.getConfig());
    }

    // Don't over fill the memory cache to avoid evicting useful resources, but make sure it's
    // not empty so
    // we use all available space.
    if (getFreeMemoryCacheBytes() >= Util.getBitmapByteSize(bitmap)) {
      memoryCache.put(new UniqueKey(), BitmapResource.obtain(bitmap, bitmapPool));
    } else {
      bitmapPool.put(bitmap);
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG,
          "allocated [" + toAllocate.getWidth() + "x" + toAllocate.getHeight() + "] " + toAllocate
              .getConfig() + " size: " + Util.getBitmapByteSize(bitmap));
    }
  }

  return !isCancelled && !toPrefill.isEmpty();
}
项目:GitHub    文件:BitmapPreFillRunner.java   
/**
 * Attempts to allocate {@link android.graphics.Bitmap}s and returns {@code true} if there are
 * more {@link android.graphics.Bitmap}s to allocate and {@code false} otherwise.
 */
private boolean allocate() {
  long start = clock.now();
  while (!toPrefill.isEmpty() && !isGcDetected(start)) {
    PreFillType toAllocate = toPrefill.remove();
    final Bitmap bitmap;
    if (!seenTypes.contains(toAllocate)) {
      seenTypes.add(toAllocate);
      bitmap = bitmapPool.getDirty(toAllocate.getWidth(), toAllocate.getHeight(),
          toAllocate.getConfig());
    } else {
      bitmap = Bitmap.createBitmap(toAllocate.getWidth(), toAllocate.getHeight(),
          toAllocate.getConfig());
    }

    // Don't over fill the memory cache to avoid evicting useful resources, but make sure it's
    // not empty so
    // we use all available space.
    if (getFreeMemoryCacheBytes() >= Util.getBitmapByteSize(bitmap)) {
      memoryCache.put(new UniqueKey(), BitmapResource.obtain(bitmap, bitmapPool));
    } else {
      bitmapPool.put(bitmap);
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG,
          "allocated [" + toAllocate.getWidth() + "x" + toAllocate.getHeight() + "] " + toAllocate
              .getConfig() + " size: " + Util.getBitmapByteSize(bitmap));
    }
  }

  return !isCancelled && !toPrefill.isEmpty();
}
项目:TestChat    文件:BlurTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
        Bitmap source = resource.get();

        int width = source.getWidth();
        int height = source.getHeight();
        int scaledWidth = width / mSampling;
        int scaledHeight = height / mSampling;

        Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        if (bitmap == null) {
                bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(source, 0, 0, paint);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                try {
                        bitmap = RSBlur.blur(mContext, bitmap, mRadius);
                } catch (RSRuntimeException e) {
                        bitmap = FastBlur.blur(bitmap, mRadius, true);
                }
        } else {
                bitmap = FastBlur.blur(bitmap, mRadius, true);
        }

        return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Hotspot-master-devp    文件:BlurTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;

    Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        try {
            bitmap = RSBlur.blur(mContext, bitmap, mRadius);
        } catch (RSRuntimeException e) {
            bitmap = FastBlur.blur(bitmap, mRadius, true);
        }
    } else {
        bitmap = FastBlur.blur(bitmap, mRadius, true);
    }

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:BlurTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();
  int scaledWidth = width / mSampling;
  int scaledHeight = height / mSampling;

  Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
  Paint paint = new Paint();
  paint.setFlags(Paint.FILTER_BITMAP_FLAG);
  canvas.drawBitmap(source, 0, 0, paint);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    try {
      bitmap = RSBlur.blur(mContext, bitmap, mRadius);
    } catch (RSRuntimeException e) {
      bitmap = FastBlur.blur(bitmap, mRadius, true);
    }
  } else {
    bitmap = FastBlur.blur(bitmap, mRadius, true);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:CropTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  mWidth = mWidth == 0 ? source.getWidth() : mWidth;
  mHeight = mHeight == 0 ? source.getHeight() : mHeight;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(mWidth, mHeight, config);
  }

  float scaleX = (float) mWidth / source.getWidth();
  float scaleY = (float) mHeight / source.getHeight();
  float scale = Math.max(scaleX, scaleY);

  float scaledWidth = scale * source.getWidth();
  float scaledHeight = scale * source.getHeight();
  float left = (mWidth - scaledWidth) / 2;
  float top = getTop(scaledHeight);
  RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

  Canvas canvas = new Canvas(bitmap);
  canvas.drawBitmap(source, null, targetRect, null);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:GPUFilterTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  GPUImage gpuImage = new GPUImage(mContext);
  gpuImage.setImage(source);
  gpuImage.setFilter(mFilter);

  Bitmap bitmap = gpuImage.getBitmapWithFilterApplied();

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:Glide-transformations    文件:CropCircleTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:GeekZone    文件:BlurTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;

    Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        try {
            bitmap = RSBlur.blur(mContext, bitmap, mRadius);
        } catch (RSRuntimeException e) {
            bitmap = FastBlur.blur(bitmap, mRadius, true);
        }
    } else {
        bitmap = FastBlur.blur(bitmap, mRadius, true);
    }

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:GlidePlus    文件:BitmapCircleTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int size = Math.min(source.getWidth(), source.getHeight());

    int width = (source.getWidth() - size) / 2;
    int height = (source.getHeight() - size) / 2;

    Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader =
            new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    if (width != 0 || height != 0) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(-width, -height);
        shader.setLocalMatrix(matrix);
    }
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:gigigo-imageLoader-library-android    文件:BlurTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();
  int scaledWidth = width / mSampling;
  int scaledHeight = height / mSampling;

  Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
  Paint paint = new Paint();
  paint.setFlags(Paint.FILTER_BITMAP_FLAG);
  canvas.drawBitmap(source, 0, 0, paint);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    try {
      bitmap = RSBlur.blur(mContext, bitmap, mRadius);
    } catch (RSRuntimeException e) {
      bitmap = FastBlur.blur(bitmap, mRadius, true);
    }
  } else {
    bitmap = FastBlur.blur(bitmap, mRadius, true);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:gigigo-imageLoader-library-android    文件:GlideCircleTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap myTransformedBitmap = cropToCircle(pool, resource.get());
  myTransformedBitmap =
      addColoredFrame(myTransformedBitmap, dimenBorder, color);
  return BitmapResource.obtain(myTransformedBitmap, pool);
}