• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java GifDecoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.bumptech.glide.gifdecoder.GifDecoder的典型用法代码示例。如果您正苦于以下问题:Java GifDecoder类的具体用法?Java GifDecoder怎么用?Java GifDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GifDecoder类属于com.bumptech.glide.gifdecoder包,在下文中一共展示了GifDecoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: GifFrameLoader

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
public GifFrameLoader(
    Glide glide,
    GifDecoder gifDecoder,
    int width,
    int height,
    Transformation<Bitmap> transformation,
    Bitmap firstFrame) {
  this(
      glide.getBitmapPool(),
      Glide.with(glide.getContext()),
      gifDecoder,
      null /*handler*/,
      getRequestBuilder(Glide.with(glide.getContext()), width, height),
      transformation,
      firstFrame);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:GifFrameLoader.java


示例2: setUp

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  gifHeader = Mockito.spy(new GifHeader());
  when(parser.parseHeader()).thenReturn(gifHeader);
  when(parserPool.obtain(isA(ByteBuffer.class))).thenReturn(parser);

  when(decoderFactory.build(isA(GifDecoder.BitmapProvider.class),
      eq(gifHeader), isA(ByteBuffer.class), anyInt()))
      .thenReturn(gifDecoder);

  List<ImageHeaderParser> parsers = new ArrayList<ImageHeaderParser>();
  parsers.add(new DefaultImageHeaderParser());

  options = new Options();
  decoder =
      new ByteBufferGifDecoder(
          RuntimeEnvironment.application,
          parsers,
          bitmapPool,
          new LruArrayPool(ARRAY_POOL_SIZE_BYTES),
          parserPool,
          decoderFactory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ByteBufferGifDecoderTest.java


示例3: GifFrameLoader

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
GifFrameLoader(
    Glide glide,
    GifDecoder gifDecoder,
    int width,
    int height,
    Transformation<Bitmap> transformation,
    Bitmap firstFrame) {
  this(
      glide.getBitmapPool(),
      Glide.with(glide.getContext()),
      gifDecoder,
      null /*handler*/,
      getRequestBuilder(Glide.with(glide.getContext()), width, height),
      transformation,
      firstFrame);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:GifFrameLoader.java


示例4: GifDrawable

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
/**
 * Constructor for GifDrawable.
 *
 * @param context             A context.
 * @param frameTransformation An {@link com.bumptech.glide.load.Transformation} that can be
 *                            applied to each frame.
 * @param targetFrameWidth    The desired width of the frames displayed by this drawable (the
 *                            width of the view or
 *                            {@link com.bumptech.glide.request.target.Target}
 *                            this drawable is being loaded into).
 * @param targetFrameHeight   The desired height of the frames displayed by this drawable (the
 *                            height of the view or
 *                            {@link com.bumptech.glide.request.target.Target}
 *                            this drawable is being loaded into).
 * @param gifDecoder          The decoder to use to decode GIF data.
 * @param firstFrame          The decoded and transformed first frame of this GIF.
 * @see #setFrameTransformation(com.bumptech.glide.load.Transformation, android.graphics.Bitmap)
 */
public GifDrawable(
    Context context,
    GifDecoder gifDecoder,
    Transformation<Bitmap> frameTransformation,
    int targetFrameWidth,
    int targetFrameHeight,
    Bitmap firstFrame) {
  this(
      new GifState(
          new GifFrameLoader(
              // TODO(b/27524013): Factor out this call to Glide.get()
              Glide.get(context),
              gifDecoder,
              targetFrameWidth,
              targetFrameHeight,
              frameTransformation,
              firstFrame)));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:GifDrawable.java


示例5: setUp

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  gifHeader = Mockito.spy(new GifHeader());
  when(parser.parseHeader()).thenReturn(gifHeader);
  when(parserPool.obtain(isA(ByteBuffer.class))).thenReturn(parser);

  when(decoderFactory.build(isA(GifDecoder.BitmapProvider.class),
      eq(gifHeader), isA(ByteBuffer.class), anyInt()))
      .thenReturn(gifDecoder);

  List<ImageHeaderParser> parsers = new ArrayList<>();
  parsers.add(new DefaultImageHeaderParser());

  options = new Options();
  decoder =
      new ByteBufferGifDecoder(
          RuntimeEnvironment.application,
          parsers,
          bitmapPool,
          new LruArrayPool(ARRAY_POOL_SIZE_BYTES),
          parserPool,
          decoderFactory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ByteBufferGifDecoderTest.java


示例6: testReturnsNewDrawableFromConstantState

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Test
public void testReturnsNewDrawableFromConstantState() {
  Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
  drawable =
      new GifDrawable(
          RuntimeEnvironment.application,
          mock(GifDecoder.class),
          transformation,
          100,
          100,
          firstFrame);

  assertNotNull(Preconditions.checkNotNull(drawable.getConstantState()).newDrawable());
  assertNotNull(
      drawable.getConstantState().newDrawable(RuntimeEnvironment.application.getResources()));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:GifDrawableTest.java


示例7: GifFrameManager

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
public GifFrameManager(Context context, GifDecoder decoder, Handler mainHandler,
        Transformation<Bitmap> transformation) {
    this.context = context;
    this.decoder = decoder;
    this.mainHandler = mainHandler;
    this.transformation = transformation;
    calculator = new MemorySizeCalculator(context);
    frameLoader = new GifFrameModelLoader();
    frameResourceDecoder = new GifFrameResourceDecoder();

    if (!decoder.isTransparent()) {
        // For non transparent gifs, we can beat the performance of our gif decoder for each frame by decoding jpegs
        // from disk.
        cacheDecoder = new StreamBitmapDecoder(context);
        encoder = new BitmapEncoder(Bitmap.CompressFormat.JPEG, 70);
    } else {
        // For transparent gifs, we would have to encode as pngs which is actually slower than our gif decoder so we
        // avoid writing frames to the disk cache entirely.
        cacheDecoder = NullCacheDecoder.get();
        encoder = SkipCache.get();
    }
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:23,代码来源:GifFrameManager.java


示例8: getNextFrame

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
public void getNextFrame(FrameCallback cb) {
    decoder.advance();
    // We don't want to blow out the entire memory cache with frames of gifs, so try to set some
    // maximum size beyond which we will always just decode one frame at a time.
    boolean skipCache = decoder.getDecodedFramesByteSizeSum() > calculator.getMemoryCacheSize() / 2;

    long targetTime = SystemClock.uptimeMillis() + (Math.min(MIN_FRAME_DELAY, decoder.getNextDelay()));
    next = new DelayTarget(decoder, cb, targetTime, mainHandler);

    Glide.with(context)
            .using(frameLoader, GifDecoder.class)
            .load(decoder)
            .as(Bitmap.class)
            .decoder(frameResourceDecoder)
            .cacheDecoder(cacheDecoder)
            .transform(transformation)
            .encoder(encoder)
            .skipMemoryCache(skipCache)
            .into(next);
}
 
开发者ID:The-WebOps-Club,项目名称:saarang-iosched,代码行数:21,代码来源:GifFrameManager.java


示例9: getRequestBuilder

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
private static GenericRequestBuilder<GifDecoder, GifDecoder, Bitmap, Bitmap> getRequestBuilder(Context context,
                                                                                               GifDecoder gifDecoder, int width, int height, BitmapPool bitmapPool) {
	GifFrameResourceDecoder frameResourceDecoder = new GifFrameResourceDecoder(bitmapPool);
	GifFrameModelLoader frameLoader = new GifFrameModelLoader();
	Encoder<GifDecoder> sourceEncoder = NullEncoder.get();
	return Glide.with(context)
			.using(frameLoader, GifDecoder.class)
			.load(gifDecoder)
			.as(Bitmap.class)
			.sourceEncoder(sourceEncoder)
			.decoder(frameResourceDecoder)
			.skipMemoryCache(true)
			.diskCacheStrategy(DiskCacheStrategy.NONE)
			.override(width, height);

}
 
开发者ID:ericleong,项目名称:tumblr3d,代码行数:17,代码来源:GifFrameLoader.java


示例10: GifState

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
public GifState(GifHeader header, byte[] data, Context context,
                Transformation<Bitmap> frameTransformation, int targetWidth, int targetHeight,
                GifDecoder.BitmapProvider provider, BitmapPool bitmapPool, Bitmap firstFrame) {
	if (firstFrame == null) {
		throw new NullPointerException("The first frame of the GIF must not be null");
	}
	gifHeader = header;
	this.data = data;
	this.bitmapPool = bitmapPool;
	this.firstFrame = firstFrame;
	this.context = context.getApplicationContext();
	this.frameTransformation = frameTransformation;
	this.targetWidth = targetWidth;
	this.targetHeight = targetHeight;
	bitmapProvider = provider;
}
 
开发者ID:ericleong,项目名称:tumblr3d,代码行数:17,代码来源:GifTexture.java


示例11: decode

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
private GifTextureResource decode(byte[] data, int width, int height, GifHeaderParser parser, GifDecoder decoder) {
	final GifHeader header = parser.parseHeader();
	if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) {
		// If we couldn't decode the GIF, we will end up with a frame count of 0.
		return null;
	}

	Bitmap firstFrame = decodeFirstFrame(decoder, header, data);
	if (firstFrame == null) {
		return null;
	}

	Transformation<Bitmap> unitTransformation = UnitTransformation.get();

	GifTexture gifDrawable = new GifTexture(context, provider, bitmapPool, unitTransformation, width, height,
			header, data, firstFrame);

	return new GifTextureResource(gifDrawable);
}
 
开发者ID:ericleong,项目名称:tumblr3d,代码行数:20,代码来源:GifResourceDecoder.java


示例12: encodeTransformedToStream

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的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


示例13: decodeHeaders

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
private GifDecoder decodeHeaders(ByteBuffer data) {
  GifHeaderParser parser = factory.buildParser();
  parser.setData(data);
  GifHeader header = parser.parseHeader();

  GifDecoder decoder = factory.buildDecoder(provider);
  decoder.setData(header, data);
  decoder.advance();

  return decoder;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ReEncodingGifResourceEncoder.java


示例14: setUp

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  Application context = RuntimeEnvironment.application;

  ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class);
  when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
  when(factory.buildParser()).thenReturn(parser);
  when(factory.buildEncoder()).thenReturn(gifEncoder);
  when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class)))
      .thenReturn(frameResource);

  // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
  when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt()))
      .thenReturn(frameResource);

  when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);
  when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0));

  when(resource.get()).thenReturn(gifDrawable);

  encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory);
  options = new Options();
  options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true);

  file = new File(context.getCacheDir(), "test");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:ReEncodingGifResourceEncoderTest.java


示例15: decode

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
private GifDrawableResource decode(ByteBuffer byteBuffer, int width, int height,
    GifHeaderParser parser) {
  long startTime = LogTime.getLogTime();
  final GifHeader header = parser.parseHeader();
  if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) {
    // If we couldn't decode the GIF, we will end up with a frame count of 0.
    return null;
  }


  int sampleSize = getSampleSize(header, width, height);
  GifDecoder gifDecoder = gifDecoderFactory.build(provider, header, byteBuffer, sampleSize);
  gifDecoder.advance();
  Bitmap firstFrame = gifDecoder.getNextFrame();
  if (firstFrame == null) {
    return null;
  }

  Transformation<Bitmap> unitTransformation = UnitTransformation.get();

  GifDrawable gifDrawable =
      new GifDrawable(context, gifDecoder, bitmapPool, unitTransformation, width, height,
          firstFrame);

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime));
  }

  return new GifDrawableResource(gifDrawable);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:ByteBufferGifDecoder.java


示例16: testReturnsNullIfGifDecoderFailsToDecodeFirstFrame

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Test
public void testReturnsNullIfGifDecoderFailsToDecodeFirstFrame() {
  when(gifHeader.getNumFrames()).thenReturn(1);
  when(gifHeader.getStatus()).thenReturn(GifDecoder.STATUS_OK);
  when(gifDecoder.getNextFrame()).thenReturn(null);

  assertNull(decoder.decode(ByteBuffer.allocate(10), 100, 100, options));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:ByteBufferGifDecoderTest.java


示例17: testReturnsNewDrawableFromConstantState

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Test
public void testReturnsNewDrawableFromConstantState() {
  Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
  drawable =
      new GifDrawable(RuntimeEnvironment.application, mock(GifDecoder.class), bitmapPool,
          transformation, 100, 100, firstFrame);

  assertNotNull(drawable.getConstantState().newDrawable());
  assertNotNull(
      drawable.getConstantState().newDrawable(RuntimeEnvironment.application.getResources()));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:GifDrawableTest.java


示例18: testLoopsForeverIfLoopCountIsLoopIntrinsicAndTotalIterationCountIsForever

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@Test
public void testLoopsForeverIfLoopCountIsLoopIntrinsicAndTotalIterationCountIsForever() {
  final int frameCount = 3;
  final int loopCount = 40;
  when(frameLoader.getLoopCount()).thenReturn(GifDecoder.TOTAL_ITERATION_COUNT_FOREVER);
  when(frameLoader.getFrameCount()).thenReturn(frameCount);
  drawable.setLoopCount(GifDrawable.LOOP_INTRINSIC);
  drawable.setVisible(true, true);
  drawable.start();

  runLoops(loopCount, frameCount);

  verifyRanLoops(loopCount, frameCount);
  assertTrue("drawable should be still running", drawable.isRunning());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:GifDrawableTest.java


示例19: setUp

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);

  Application context = RuntimeEnvironment.application;

  ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class);
  when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
  when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
  when(factory.buildParser()).thenReturn(parser);
  when(factory.buildEncoder()).thenReturn(gifEncoder);
  when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class)))
      .thenReturn(frameResource);

  // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
  when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt()))
      .thenReturn(frameResource);

  when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation);
  when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0));

  when(resource.get()).thenReturn(gifDrawable);

  encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory);
  options = new Options();
  options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true);

  file = new File(context.getCacheDir(), "test");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:ReEncodingGifResourceEncoderTest.java


示例20: decode

import com.bumptech.glide.gifdecoder.GifDecoder; //导入依赖的package包/类
private GifDrawableResource decode(
    ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser, Options options) {
  long startTime = LogTime.getLogTime();
  final GifHeader header = parser.parseHeader();
  if (header.getNumFrames() <= 0 || header.getStatus() != GifDecoder.STATUS_OK) {
    // If we couldn't decode the GIF, we will end up with a frame count of 0.
    return null;
  }

  Bitmap.Config config = options.get(GifOptions.DECODE_FORMAT) == DecodeFormat.PREFER_RGB_565
      ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;

  int sampleSize = getSampleSize(header, width, height);
  GifDecoder gifDecoder = gifDecoderFactory.build(provider, header, byteBuffer, sampleSize);
  gifDecoder.setDefaultBitmapConfig(config);
  gifDecoder.advance();
  Bitmap firstFrame = gifDecoder.getNextFrame();
  if (firstFrame == null) {
    return null;
  }

  Transformation<Bitmap> unitTransformation = UnitTransformation.get();

  GifDrawable gifDrawable =
      new GifDrawable(context, gifDecoder, unitTransformation, width, height, firstFrame);

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    Log.v(TAG, "Decoded GIF from stream in " + LogTime.getElapsedMillis(startTime));
  }

  return new GifDrawableResource(gifDrawable);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:ByteBufferGifDecoder.java



注:本文中的com.bumptech.glide.gifdecoder.GifDecoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DebuggerManager类代码示例发布时间:2022-05-23
下一篇:
Java Configurable类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap