Java 类com.bumptech.glide.load.DecodeFormat 实例源码

项目:GitHub    文件:Downsampler.java   
/**
 * Returns a Bitmap decoded from the given {@link InputStream} that is rotated to match any EXIF
 * data present in the stream and that is downsampled according to the given dimensions and any
 * provided  {@link com.bumptech.glide.load.resource.bitmap.DownsampleStrategy} option.
 *
 * <p> If a Bitmap is present in the
 * {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool} whose dimensions exactly match
 * those of the image for the given InputStream is available, the operation is much less expensive
 * in terms of memory. </p>
 *
 * <p> The provided {@link java.io.InputStream} must return <code>true</code> from
 * {@link java.io.InputStream#markSupported()} and is expected to support a reasonably large
 * mark limit to accommodate reading large image headers (~5MB). </p>
 *
 * @param is        An {@link InputStream} to the data for the image.
 * @param requestedWidth  The width the final image should be close to.
 * @param requestedHeight The height the final image should be close to.
 * @param options   A set of options that may contain one or more supported options that influence
 *                  how a Bitmap will be decoded from the given stream.
 * @param callbacks A set of callbacks allowing callers to optionally respond to various
 *                  significant events during the decode process.
 * @return A new bitmap containing the image from the given InputStream, or recycle if recycle is
 * not null.
 */
@SuppressWarnings("resource")
public Resource<Bitmap> decode(InputStream is, int requestedWidth, int requestedHeight,
    Options options, DecodeCallbacks callbacks) throws IOException {
  Preconditions.checkArgument(is.markSupported(), "You must provide an InputStream that supports"
      + " mark()");

  byte[] bytesForOptions = byteArrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, byte[].class);
  BitmapFactory.Options bitmapFactoryOptions = getDefaultOptions();
  bitmapFactoryOptions.inTempStorage = bytesForOptions;

  DecodeFormat decodeFormat = options.get(DECODE_FORMAT);
  DownsampleStrategy downsampleStrategy = options.get(DOWNSAMPLE_STRATEGY);
  boolean fixBitmapToRequestedDimensions = options.get(FIX_BITMAP_SIZE_TO_REQUESTED_DIMENSIONS);

  try {
    Bitmap result = decodeFromWrappedStreams(is, bitmapFactoryOptions,
        downsampleStrategy, decodeFormat, requestedWidth, requestedHeight,
        fixBitmapToRequestedDimensions, callbacks);
    return BitmapResource.obtain(result, bitmapPool);
  } finally {
    releaseOptions(bitmapFactoryOptions);
    byteArrayPool.put(bytesForOptions, byte[].class);
  }
}
项目:GitHub    文件:Downsampler.java   
private Bitmap.Config getConfig(InputStream is, DecodeFormat format) throws IOException {
  // Changing configs can cause skewing on 4.1, see issue #128.
  if (format == DecodeFormat.PREFER_ARGB_8888
      || Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
    return Bitmap.Config.ARGB_8888;
  }

  boolean hasAlpha = false;
  try {
    hasAlpha = ImageHeaderParserUtils.getType(parsers, is, byteArrayPool).hasAlpha();
  } catch (IOException e) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Cannot determine whether the image has alpha or not from header"
          + ", format " + format, e);
    }
  }

  return hasAlpha ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
}
项目:GitHub    文件:BitmapPreFiller.java   
public void preFill(PreFillType.Builder... bitmapAttributeBuilders) {
  if (current != null) {
    current.cancel();
  }

  PreFillType[] bitmapAttributes = new PreFillType[bitmapAttributeBuilders.length];
  for (int i = 0; i < bitmapAttributeBuilders.length; i++) {
    PreFillType.Builder builder = bitmapAttributeBuilders[i];
    if (builder.getConfig() == null) {
      builder.setConfig(defaultFormat == DecodeFormat.PREFER_ARGB_8888
          ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    bitmapAttributes[i] = builder.build();
  }

  PreFillQueue allocationOrder = generateAllocationOrder(bitmapAttributes);
  current = new BitmapPreFillRunner(bitmapPool, memoryCache, allocationOrder);
  handler.post(current);
}
项目:GitHub    文件:BitmapPreFiller.java   
@SuppressWarnings("deprecation")
public void preFill(PreFillType.Builder... bitmapAttributeBuilders) {
  if (current != null) {
    current.cancel();
  }

  PreFillType[] bitmapAttributes = new PreFillType[bitmapAttributeBuilders.length];
  for (int i = 0; i < bitmapAttributeBuilders.length; i++) {
    PreFillType.Builder builder = bitmapAttributeBuilders[i];
    if (builder.getConfig() == null) {
      builder.setConfig(
          defaultFormat == DecodeFormat.PREFER_ARGB_8888
              || defaultFormat == DecodeFormat.PREFER_ARGB_8888_DISALLOW_HARDWARE
          ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    bitmapAttributes[i] = builder.build();
  }

  PreFillQueue allocationOrder = generateAllocationOrder(bitmapAttributes);
  current = new BitmapPreFillRunner(bitmapPool, memoryCache, allocationOrder);
  handler.post(current);
}
项目:MVVMFrames    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {

    // 缓存目录
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            AppComponent component = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.cacheFile(), "Glide")), DISK_SIZE);
        }
    });

    // 自定义内存缓存和图片池大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    builder.setMemoryCache(new LruResourceCache((int) (1.2 * calculator.getMemoryCacheSize())));
    builder.setBitmapPool(new LruBitmapPool((int) (1.2 * calculator.getBitmapPoolSize())));

    // 图片格式
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认
}
项目: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();
}
项目:leisure-glance    文件:GalleryActivity.java   
@Override
public Object instantiateItem(ViewGroup container, int position) {
    if (photos == null) {
        return null;
    }
    if (mViews == null) {
        mViews = new PhotoView[photos.size()];
        for (int i = 0; i < 4; i++) {
            mViews[i] = new PhotoView(container.getContext());
            mViews[i].setBackgroundColor(Color.BLACK);
        }
    }
    if (mViews[position] == null) {
        mViews[position] = mViews[position % 4];
    }
    container.addView(mViews[position], ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    Log.e("TAG", "addView: " + position);
    GlideApp.with(GalleryActivity.this)
            .load(photos.get(position))
            .format(DecodeFormat.PREFER_ARGB_8888)
            .diskCacheStrategy(DiskCacheStrategy.DATA)
            .into(mViews[position]);

    return mViews[position];
}
项目:GeekZone    文件:GlideConfiguration.java   
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    // Get default memory cache size
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    // Set custom memory cache size
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.5 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    // Set disk cache size
    int diskCacheSize = 1024 * 1024 * 100;
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", diskCacheSize));

    // Prefer higher quality images unless we're on a low RAM device
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    builder.setDecodeFormat(activityManager.isLowRamDevice() ?
            DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
}
项目:anitrend-app    文件:ConfigModule.java   
/**
 * Lazily apply options to a {@link GlideBuilder} immediately before the Glide singleton is
 * created.
 * <p>
 * <p>
 * This method will be called once and only once per implementation.
 * </p>
 *
 * @param context An Application {@link Context}.
 * @param builder The {@link GlideBuilder} that will be used to create Glide.
 */
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    // Increasing cache & pool by 25% - default is 250MB
    int memoryCacheSize = (int) (1.25 * calculator.getMemoryCacheSize());
    int bitmapPoolSize = (int) (1.25 * calculator.getBitmapPoolSize());
    int storageCacheSize = 1024 * 1024 * 350;
    if(context.getExternalCacheDir() != null) {
        long total = context.getExternalCacheDir().getUsableSpace();
        storageCacheSize = (int) (total*0.14);
    }

    builder.setMemoryCache(new LruResourceCache(memoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize));
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, storageCacheSize));
    builder.setDecodeFormat(ActivityManagerCompat.isLowRamDevice(activityManager) ?
            DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
}
项目: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();
}
项目:nuclei-android    文件:AlbumArtCache.java   
public Bitmap fetchIconSync(Context context, String artUrl) {
    ActivityManager mgr = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && mgr.isLowRamDevice())
        return null;
    int memoryClass = mgr.getMemoryClass();
    int widthIcon = MAX_ART_WIDTH_ICON;
    int heightIcon = MAX_ART_HEIGHT_ICON;
    if (memoryClass <= MEMORY_CLASS) {
        widthIcon /= 2;
        heightIcon /= 2;
    }
    try {
        return Glide.with(context)
                .load(artUrl)
                .asBitmap()
                .dontAnimate()
                .dontTransform()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .format(DecodeFormat.PREFER_RGB_565)
                .into(widthIcon, heightIcon)
                .get();
    } catch (Exception err) {
        return null;
    }
}
项目:GlideDemo    文件:SimpleGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //定义缓存大小为100M
    int  diskCacheSize =  100 * 1024 * 1024;

    //自定义缓存 路径 和 缓存大小
    String diskCachePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/glideCache" ;

    //提高图片质量
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);

    //自定义磁盘缓存:这种缓存只有自己的app才能访问到
    // builder.setDiskCache( new InternalCacheDiskCacheFactory( context , diskCacheSize )) ;
    // builder.setDiskCache( new InternalCacheDiskCacheFactory( context , diskCachePath , diskCacheSize  )) ;

    //自定义磁盘缓存:这种缓存存在SD卡上,所有的应用都可以访问到
    builder.setDiskCache(new DiskLruCacheFactory( diskCachePath , diskCacheSize ));

}
项目:aptoide-client-v8    文件:GlideModifications.java   
@Override public void applyOptions(Context context, GlideBuilder builder) {
  builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);

  // disk cache config
  //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context));
  // using defaults

  MemorySizeCalculator calculator = new MemorySizeCalculator(context);

  // size for memory cache
  int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
  builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize));

  // size for bitmap pool
  int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
  builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize));
}
项目:glide-support    文件:TestFragment.java   
@Override protected void load(Context context) throws Exception {
    String url = "http://www.online-image-editor.com//styles/2014/images/example_image.png";
    String url2 =
            "http://a5.mzstatic.com/us/r30/Purple5/v4/5a/2e/e9/5a2ee9b3-8f0e-4f8b-4043-dd3e3ea29766/icon128-2x.png";
    BitmapRequestBuilder<String, Bitmap> request = Glide
            .with(context)
            .load(url)
            .asBitmap()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .thumbnail(Glide
                    .with(context)
                    .load(url2)
                    .asBitmap()
            );
    loadProper(request);
    loadHacky(request);
    loadHackyAlt(request);
}
项目:glide-support    文件:TestFragment_Inclusive.java   
@Override public void onAttach(Context context) {
    super.onAttach(context);
    BitmapPool pool = Glide.get(context).getBitmapPool();
    StreamBitmapDecoder bitmapDecoder = new StreamBitmapDecoder(Downsampler.AT_LEAST, pool, DecodeFormat.DEFAULT);
    paletteLoad = Glide
            .with(this)
            .using(new StreamUriLoader(context), InputStream.class)
            .from(Uri.class)
            .as(PaletteBitmap.class)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .encoder(new PaletteBitmapEncoder(new BitmapEncoder(), new PaletteEncoder()))
            .sourceEncoder(new StreamEncoder())
            .cacheDecoder(new FileToStreamDecoder<>(
                    new PaletteBitmapDecoder(pool, bitmapDecoder, new PaletteDecoder())))
            .dontAnimate()
            .skipMemoryCache(true) // debug to always go for disk
    ;
}
项目:glide-support    文件:TestFragment_Separate.java   
@Override public void onAttach(Context context) {
    super.onAttach(context);
    paletteLoad = Glide
            .with(this)
            .using(new StreamUriLoader(context), InputStream.class)
            .from(Uri.class)
            .as(Palette.class)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .encoder(new PaletteCacheEncoder(new PaletteEncoder()))
            .sourceEncoder(new StreamEncoder())
            .cacheDecoder(new FileToStreamDecoder<>(
                    new PaletteCacheDecoder(new PaletteDecoder(), new StreamBitmapDecoder(
                            Downsampler.AT_MOST, Glide.get(context).getBitmapPool(), DecodeFormat.DEFAULT))))
            .override(256, 256) // rough size of the Bitmap to generate Palette from 
            .dontTransform() // default, but be explicit
            .dontAnimate() // default, but be explicit
            .skipMemoryCache(true) // debug to always go for disk
    ;
}
项目:ImageSwitcher    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 设置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 缓存到data目录下最大50M
    // 缓存目录为程序内部缓存目录
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它应用访问)且缓存最大为250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 缓存到外部磁盘SD卡上,字节
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 设置内存缓存大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
项目:GankGirl    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);// Bitmap格式转换到ARGB_8888
    //内存缓存
    MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = memorySizeCalculator.getMemoryCacheSize();
    int defalutBitmapPoolSize = memorySizeCalculator.getBitmapPoolSize();
    builder.setMemoryCache(new LruResourceCache((int) (defalutBitmapPoolSize * 1.2)));//内部
    builder.setBitmapPool(new LruBitmapPool((int) (defalutBitmapPoolSize * 1.2)));
    //磁盘缓存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 1024 * 1024 * 10));//内部磁盘缓存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 10 * 1024 * 1024));//磁盘缓存到外部存储
    //指定缓存目录1
    String downLoadPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(new DiskLruCacheFactory(downLoadPath, defaultMemoryCacheSize));
    //指定缓存目录2
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File cacheLocation = new File(FileUtils.getCacheDir(context), "GlideCache");
            return DiskLruCacheWrapper.get(cacheLocation, 1024 * 1024 * 10);
        }
    });

}
项目:FriendCircle    文件:GlobalGlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    //解决setTag问题
    ViewTarget.setTagId(R.id.glide_tag_id);
    //磁盘缓存
    builder.setDiskCache(new DiskLruCacheFactory(AppFileHelper.getAppCachePath(), 50 * 1024 * 1024));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    //内存缓存
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    //设置比默认大小大1.5倍的缓存和图片池大小
    int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize);
    int customBitmapPoolSize = defaultBitmapPoolSize;


    KLog.i("poolSize", "bitmapPoolSize >>>>>   "
            + android.text.format.Formatter.formatFileSize(context, customBitmapPoolSize)
            + "          memorySize>>>>>>>>   " +
            android.text.format.Formatter.formatFileSize(context, customMemoryCacheSize));

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
项目:WhiteRead    文件:GlideConfigModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 指定位置在packageName/cache/glide_cache,大小为MAX_CACHE_DISK_SIZE的磁盘缓存
    // 设置一个用来创建DiskCache的工厂。默认情况下Glide使用InternalCacheDiskCacheFactory内部工厂类创建DiskCache,
    // 缓存目录为程序内部缓存目录/data/data/your_package_name/image_manager_disk_cache/(不能被其它应用访问)且缓存最大为250MB。
    // 当然,可以通过InternalCacheDiskCacheFactory构造器更改缓存的目录和最大缓存大小
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide_cache", ConfigConstants.MAX_CACHE_DISK_SIZE));
    // 指定内存缓存大小
    // MemoryCache用来把resources 缓存在内存里,以便能马上能拿出来显示。
    // 默认情况下Glide使用LruResourceCache,我们可以通过它的构造器设置最大缓存内存大小。
    builder.setMemoryCache(new LruResourceCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
    // 全部的内存缓存用来作为图片缓存
    // Bitmap池用来允许不同尺寸的Bitmap被重用,这可以显著地减少因为图片解码像素数组分配内存而引发的垃圾回收。
    // 默认情况下Glide使用LruBitmapPool作为Bitmap池,LruBitmapPool采用LRU算法保存最近使用的尺寸的Bitmap。
    // 我们可以通过它的构造器设置最大缓存内存大小。
    builder.setBitmapPool(new LruBitmapPool(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
    // 为所有的默认解码器设置解码格式。如DecodeFormat.PREFER_ARGB_8888。
    // 默认是DecodeFormat.PREFER_RGB_565,因为相对于ARGB_8888的4字节/像素可以节省一半的内存,但不支持透明度且某些图片会出现条带。
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);//和Picasso配置一样
}
项目:GankMeiZhi    文件:MyGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache( new LruResourceCache( customMemoryCacheSize ));
    builder.setBitmapPool( new LruBitmapPool( customBitmapPoolSize ));

    int cacheSize50MegaBytes = 52428800;

    /*builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)
    );*/

    /*builder.setDiskCache(
    new ExternalCacheDiskCacheFactory());*/
    builder.setDiskCache(new DiskLruCacheFactory(Constants.OwnCacheDirectory,"Cache",cacheSize50MegaBytes)) ;
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); //PREFER_RGB_565
}
项目:ImageLoaders    文件:PhotoActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);
    ButterKnife.bind(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);

    url = getIntent().getStringExtra("url");
    photo.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);
    Glide.with(this)
            .load(url)
            .asBitmap()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .into(photo);
}
项目:ImageLoaderDemo    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 设置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 缓存到data目录下最大50M
    // 缓存目录为程序内部缓存目录
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它应用访问)且缓存最大为250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 缓存到外部磁盘SD卡上,字节
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 设置内存缓存大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);
    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));
}
项目:BandWith    文件:GlideCustomModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Apply options to the builder here.
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);

    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    int cacheSize100MegaBytes = 104857600;
    String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(
            new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes)
    );
}
项目: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();
}
项目:MoeGallery    文件:GalleryAdapter.java   
void bind(int position) {
    mPosition = position;
    mImage = mImageDataSource.get(position);

    if (Utils.isGif(mImage.getFileUrl())) {
        gifTag.setVisibility(VISIBLE);
    } else {
        gifTag.setVisibility(GONE);
    }

    mRequestManager.load(mImage.getPreviewUrl())
            .asBitmap()
            .format(DecodeFormat.PREFER_RGB_565)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.color.gray_overlay)
            .fitCenter().centerCrop().into(imageView);
}
项目:ImageLoaders    文件:PhotoActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);
    ButterKnife.bind(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);

    url = getIntent().getStringExtra("url");
    photo.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);
    Glide.with(this)
            .load(url)
            .asBitmap()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .into(photo);
}
项目:Material-Glass    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    boolean runsMinSDK = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
    boolean enableHDWalls = context.getResources().getBoolean(R.bool.high_definition_walls);

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean lowRAMDevice = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        lowRAMDevice = activityManager.isLowRamDevice();
    }

    if (runsMinSDK) {
        if (lowRAMDevice) {
            builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
        } else {
            if (enableHDWalls) {
                builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
            } else {
                builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
            }
        }
    } else {
        builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
    }
}
项目:GitHub    文件:DownsamplerTest.java   
@Test
public void testAlwaysArgb8888() throws IOException {
  Bitmap rgb565 = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
  InputStream stream = compressBitmap(rgb565, Bitmap.CompressFormat.JPEG);

  options.set(Downsampler.DECODE_FORMAT, DecodeFormat.PREFER_ARGB_8888);
  Resource<Bitmap> result = downsampler.decode(stream, 100, 100, options);
  assertEquals(Bitmap.Config.ARGB_8888, result.get().getConfig());
}
项目:GitHub    文件:DownsamplerTest.java   
@Test
public void testPreferRgb565() throws IOException {
  Bitmap rgb565 = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
  InputStream stream = compressBitmap(rgb565, Bitmap.CompressFormat.JPEG);

  options.set(Downsampler.DECODE_FORMAT, DecodeFormat.PREFER_RGB_565);
  Resource<Bitmap> result = downsampler.decode(stream, 100, 100, options);
  assertEquals(Bitmap.Config.RGB_565, result.get().getConfig());
}
项目:GitHub    文件:BitmapPreFillerTest.java   
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  when(pool.getMaxSize()).thenReturn(poolSize);
  when(pool.getDirty(anyInt(), anyInt(), any(Bitmap.Config.class)))
      .thenAnswer(new CreateBitmap());
  when(cache.getMaxSize()).thenReturn(cacheSize);

  bitmapPreFiller = new BitmapPreFiller(cache, pool, DecodeFormat.DEFAULT);
}
项目:GitHub    文件:BitmapPreFillerTest.java   
@Test
public void testSetsConfigOnBuildersToDefaultIfNotSet() {
  PreFillType.Builder builder = mock(PreFillType.Builder.class);
  when(builder.build())
      .thenReturn(new PreFillType.Builder(100).setConfig(Bitmap.Config.RGB_565).build());

  bitmapPreFiller.preFill(builder);

  InOrder order = inOrder(builder);
  order.verify(builder).setConfig(DecodeFormat.DEFAULT == DecodeFormat.PREFER_ARGB_8888
      ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
  order.verify(builder).build();
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}
项目:GitHub    文件:GlideRequest.java   
/**
 * @see GlideOptions#format(DecodeFormat)
 */
@CheckResult
public GlideRequest<TranscodeType> format(@NonNull DecodeFormat arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).format(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).format(arg0);
  }
  return this;
}