本文整理汇总了Java中com.bumptech.glide.load.DecodeFormat类的典型用法代码示例。如果您正苦于以下问题:Java DecodeFormat类的具体用法?Java DecodeFormat怎么用?Java DecodeFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DecodeFormat类属于com.bumptech.glide.load包,在下文中一共展示了DecodeFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
/**
* 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);
}
}
示例2: getConfig
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
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;
}
示例3: preFill
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
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);
}
示例4: preFill
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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);
}
示例5: applyOptions
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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); // 默认
}
示例6: createScaledBitmapInto
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
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();
}
示例7: createScaledBitmapInto
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
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();
}
示例8: instantiateItem
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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];
}
示例9: applyOptions
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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);
}
示例10: applyOptions
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
/**
* 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);
}
示例11: fetchIconSync
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
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;
}
}
示例12: applyOptions
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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 ));
}
示例13: applyOptions
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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));
}
示例14: load
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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);
}
示例15: onAttach
import com.bumptech.glide.load.DecodeFormat; //导入依赖的package包/类
@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
;
}