Glide.with(context).load(...).asBitmap() //显示gif静态图片 Glide.with(context).load(...).asGif() //显示gif动态图片
Glide.with(context).load(“视频路径“)(经过我的测试,只能把手机本地的mp4视频解析为一张图片,把mp4文件放在raw文件中,不能解析)
//加载yourView1/10尺寸的缩略图,然后加载全图 Glide.with(yourFragment).load(yourUrl).thumbnail(0.1f).into(yourView)
Glide.with(context)
.load(“/user/profile/photo/path”)
.asBitmap()
.toBytes()
.centerCrop()
.into(new SimpleTarget<byte[]>(250, 250) {
@Override
public void onResourceReady(byte[] data, GlideAnimation anim) {
// Post your bytes to a background thread and upload them here.
}
});
(.animate(ViewPropertyAnimation.Animator))
Glide.with(yourFragment) .load(yourFileDataModel) .signature(new StringSignature(yourVersionMetadata)) .into(yourImageView); Glide.with(fragment) .load(mediaStoreUri) .signature(new MediaStoreSignature(mimeType, dateModified, orientation)) .into(view);
public class IntegerVersionSignature implements Key {
private int currentVersion;
public IntegerVersionSignature(int currentVersion) {
this.currentVersion = currentVersion;
}
@Override
public boolean equals(Object o) {
if (o instanceof IntegerVersionSignature) {
IntegerVersionSignature other = (IntegerVersionSignature) o;
return currentVersion = other.currentVersion;
}
return false;
}
@Override
public int hashCode() {
return currentVersion;
}
@Override
public void updateDiskCacheKey(MessageDigest md) {
messageDigest.update(ByteBuffer.allocate(Integer.SIZE)
.putInt(signature).array());
}
}
public class MyGlideModule implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// Apply options to the builder here.
}
@Override
public void registerComponents(Context context, Glide glide) {
// register ModelLoaders here.
}
}
-keepnames class * com.mypackage.MyGlideModule
<meta-data android:name="com.bumptech.glide.samples.flickr.FlickrGlideModule" android:value="GlideModule" />
<meta-data android:name=”com.mypackage.MyGlideModule” tools:node=”remove”/>
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, yourSizeInBytes));
builder .setDiskCache(new DiskCache.Factory() {
@Override
public DiskCache build() {
// Careful: the external cache directory doesn't enforce permissions
File cacheLocation = new File(context.getExternalCacheDir(), "cache_dir_name");
cacheLocation.mkdirs();
return DiskLruCacheWrapper.get(cacheLocation, yourSizeInBytes);
}
});
MemorySizeCalculator calculator = new MemorySizeCalculator(context); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
Glide.get(context).setMemoryCategory(MemoryCategory.HIGH);
builder.setMemoryCache(new LruResourceCache(yourSizeInBytes));
builder.setBitmapPool(new LruBitmapPool(sizeInBytes));
builder.setDecodeFormat(DecodeFormat.ALWAYS_ARGB_8888);
onResourceReady(R resource,GlideAnimation<? super R> glideAnimation)
int myWidth = 512;
int myHeight = 384;
Glide.with(yourApplicationContext))
.load(youUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
}
};
Glide.with(yourFragment)
.load(yourUrl)
.into(new ViewTarget<YourViewClass, GlideDrawable>(yourViewObject) {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation anim) {
YourViewClass myView = this.view;
// Set your resource on myView and/or start your animation here.
}
});
Glide.with(yourFragment)
.load(yourUrl)
.asBitmap()
.into(new BitmapImageViewTarget(yourImageView)) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
super.onResourceReady(bitmap, anim);
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// Here's your generated palette
}
});
}
});
public interface MyDataModel {
public String buildUrl(int width, int height);
}
public class MyUrlLoader extends BaseGlideUrlLoader<MyDataModel> {
@Override
protected String getUrl(MyDataModel model, int width, int height) {
// Construct the url for the correct size here.
return model.buildUrl(width, height);
}
}
Glide.with(yourFragment) .using(new MyUrlLoader()) .load(yourModel) .into(yourView);
ModelLoaderFactory然后使用Glide将它注册到GlideModule当中
public class MyGlideModule implements GlideModule {
...
@Override
public void registerComponents(Context context, Glide glide) {
glide.register(MyDataModel.class, InputStream.class,
new MyUrlLoader.Factory());
}
}
Glide.with(yourFragment) .load(yourModel) .into(yourView);
dependencies {
compile 'com.github.bumptech.glide:volley-integration:1.2.2'
compile 'com.mcxiaoke.volley:library:1.0.5'
}
<meta-data android:name="com.bumptech.glide.integration.volley.VolleyGlideModule" android:value="GlideModule" />
-keep class com.bumptech.glide.integration.volley.VolleyGlideModule #or -keep public class * implements com.bumptech.glide.module.GlideModule
dependencies {
compile 'com.github.bumptech.glide:okhttp-integration:1.2.2'
compile 'com.squareup.okhttp:okhttp:2.0.0'
}
<meta-data android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule" android:value="GlideModule" />
-keep class com.bumptech.glide.integration.okhttp.OkHttpGlideModule #or -keep public class * implements com.bumptech.glide.module.GlideModule
downloadOnly(int width, int height) downloadOnly(Y target)// Y extends Target<File> into(int width, int height)
FutureTarget<File> future = Glide.with(applicationContext) .load(yourUrl) .downloadOnly(500, 500); File cacheFile = future.get();
Glide.with(yourFragment) .load(yourUrl) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(yourView);
Bitmap myBitmap = Glide.with(applicationContext) .load(yourUrl) .asBitmap() .centerCrop() .into(500, 500) .get()
Glide.with(yourFragment) .load(yourUrl) .fitCenter() .into(yourView); Glide.with(yourFragment) .load(yourUrl) .centerCrop() .into(yourView); // For Bitmaps: Glide.with(yourFragment) .load(yourUrl) .asBitmap() .centerCrop() .into(yourView); // For gifs: Glide.with(yourFragment) .load(yourUrl) .asGif() .fitCenter() .into(yourView);
Glide.with(yourFragment)
.load(yourUrl)
.asBitmap()
.toBytes()
.centerCrop()
.into(new SimpleTarget<byte[]>(...) { ... });
private static class MyTransformation extends BitmapTransformation {
public MyTransformation(Context context) {
super(context);
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
int outWidth, int outHeight) {
Bitmap myTransformedBitmap = ... // apply some transformation here.
return myTransformedBitmap;
}
@Override
public String getId() {
// Return some id that uniquely identifies your transformation.
return "com.example.myapp.MyTransformation";
}
}
Glide.with(yourFragment) .load(yourUrl) .transform(new MyTransformation(context)) .into(yourView); // For Bitmaps: Glide.with(yourFragment) .load(yourUrl) .asBitmap() .transform(new MyTransformation(context)) .into(yourView); // For Gifs: Glide.with(yourFragment) .load(yourUrl) .asGif() .transform(new MyTransformation(context)) .into(yourView);
protected Bitmap transform(BitmapPool bitmapPool, Bitmap original, int width, int height) {
Bitmap result = bitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
// If no matching Bitmap is in the pool, get will return null, so we should //allocate.
if (result == null) {
// Use ARGB_8888 since we're going to add alpha to the image.
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
// Create a Canvas backed by the result Bitmap.
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setAlpha(128);
// Draw the original Bitmap onto the result Bitmap with a transformation.
canvas.drawBitmap(original, 0, 0, paint);
// Since we've replaced our original Bitmap, we return our new Bitmap here. Glide will
// will take care of returning our original Bitmap to the BitmapPool for us.
return result;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有