當前位置: 首頁>>代碼示例>>Java>>正文


Java Resource.recycle方法代碼示例

本文整理匯總了Java中com.bumptech.glide.load.engine.Resource.recycle方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.recycle方法的具體用法?Java Resource.recycle怎麽用?Java Resource.recycle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.bumptech.glide.load.engine.Resource的用法示例。


在下文中一共展示了Resource.recycle方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: transform

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GifDrawableTransformation.java

示例2: transform

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@Override
public Resource<Drawable> transform(Context context, Resource<Drawable> resource, int outWidth,
    int outHeight) {
  BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
  Drawable drawable = resource.get();
  Resource<Bitmap> bitmapResourceToTransform =
      DrawableToBitmapConverter.convert(bitmapPool, drawable, outWidth, outHeight);
  if (bitmapResourceToTransform == null) {
    if (isRequired) {
      throw new IllegalArgumentException("Unable to convert " + drawable + " to a Bitmap");
    } else {
      return resource;
    }
  }
  Resource<Bitmap> transformedBitmapResource =
      wrapped.transform(context, bitmapResourceToTransform, outWidth, outHeight);

  if (transformedBitmapResource.equals(bitmapResourceToTransform)) {
    transformedBitmapResource.recycle();
    return resource;
  } else {
    return newDrawableResource(context, transformedBitmapResource.get());
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:DrawableTransformation.java

示例3: encodeTransformedToStream

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
private boolean encodeTransformedToStream(GifDrawable drawable, OutputStream os) {
  Transformation<Bitmap> transformation = drawable.getFrameTransformation();
  GifDecoder decoder = decodeHeaders(drawable.getBuffer());
  AnimatedGifEncoder encoder = factory.buildEncoder();
  if (!encoder.start(os)) {
    return false;
  }

  for (int i = 0; i < decoder.getFrameCount(); i++) {
    Bitmap currentFrame = decoder.getNextFrame();
    Resource<Bitmap> transformedResource =
        getTransformedFrame(currentFrame, transformation, drawable);
    try {
      if (!encoder.addFrame(transformedResource.get())) {
        return false;
      }
      int currentFrameIndex = decoder.getCurrentFrameIndex();
      int delay = decoder.getDelay(currentFrameIndex);
      encoder.setDelay(delay);

      decoder.advance();
    } finally {
      transformedResource.recycle();
    }
  }

  return encoder.finish();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:ReEncodingGifResourceEncoder.java

示例4: getTransformedFrame

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
private Resource<Bitmap> getTransformedFrame(Bitmap currentFrame,
    Transformation<Bitmap> transformation, GifDrawable drawable) {
  // TODO: what if current frame is null?
  Resource<Bitmap> bitmapResource = factory.buildFrameResource(currentFrame, bitmapPool);
  Resource<Bitmap> transformedResource =
      transformation.transform(
          context, bitmapResource, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
  if (!bitmapResource.equals(transformedResource)) {
    bitmapResource.recycle();
  }
  return transformedResource;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:ReEncodingGifResourceEncoder.java

示例5: transcode

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@Override
public Resource<byte[]> transcode(Resource<Bitmap> toTranscode) {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  toTranscode.get().compress(compressFormat, quality, os);
  toTranscode.recycle();
  return new BytesResource(os.toByteArray());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:BitmapBytesTranscoder.java

示例6: transform

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@Override
public Resource<T> transform(
    Context context, Resource<T> resource, int outWidth, int outHeight) {
  Resource<T> previous = resource;

  for (Transformation<T> transformation : transformations) {
    Resource<T> transformed = transformation.transform(context, previous, outWidth, outHeight);
    if (previous != null && !previous.equals(resource) && !previous.equals(transformed)) {
      previous.recycle();
    }
    previous = transformed;
  }
  return previous;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:MultiTransformation.java

示例7: transcode

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@Override
public Resource<byte[]> transcode(Resource<Bitmap> toTranscode, Options options) {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  toTranscode.get().compress(compressFormat, quality, os);
  toTranscode.recycle();
  return new BytesResource(os.toByteArray());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:BitmapBytesTranscoder.java

示例8: recycle

import com.bumptech.glide.load.engine.Resource; //導入方法依賴的package包/類
@Override
public void recycle() {
    Resource<Bitmap> bitmapResource = data.getBitmapResource();
    if (bitmapResource != null) {
        bitmapResource.recycle();
    }
    Resource<GifDrawable> gifDataResource = data.getGifResource();
    if (gifDataResource != null) {
        gifDataResource.recycle();
    }
}
 
開發者ID:dengyuhan,項目名稱:GlidePlus,代碼行數:12,代碼來源:ImageWrapperResource.java


注:本文中的com.bumptech.glide.load.engine.Resource.recycle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。