本文整理匯總了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
;
}