com.bumptech.glide.load.resource.bitmap.Downsampler Java Examples
The following examples show how to use
com.bumptech.glide.load.resource.bitmap.Downsampler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignalGlideModule.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) { AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(); byte[] secret = attachmentSecret.getModernKey(); registry.prepend(File.class, File.class, UnitModelLoader.Factory.getInstance()); registry.prepend(InputStream.class, new EncryptedCacheEncoder(secret, glide.getArrayPool())); registry.prepend(File.class, Bitmap.class, new EncryptedBitmapCacheDecoder(secret, new StreamBitmapDecoder(new Downsampler(registry.getImageHeaderParsers(), context.getResources().getDisplayMetrics(), glide.getBitmapPool(), glide.getArrayPool()), glide.getArrayPool()))); registry.prepend(File.class, GifDrawable.class, new EncryptedGifCacheDecoder(secret, new StreamGifDecoder(registry.getImageHeaderParsers(), new ByteBufferGifDecoder(context, registry.getImageHeaderParsers(), glide.getBitmapPool(), glide.getArrayPool()), glide.getArrayPool()))); registry.prepend(BlurHash.class, Bitmap.class, new BlurHashResourceDecoder()); registry.prepend(Bitmap.class, new EncryptedBitmapResourceEncoder(secret)); registry.prepend(GifDrawable.class, new EncryptedGifDrawableResourceEncoder(secret)); registry.append(ContactPhoto.class, InputStream.class, new ContactPhotoLoader.Factory(context)); registry.append(DecryptableUri.class, InputStream.class, new DecryptableStreamUriLoader.Factory(context)); registry.append(AttachmentModel.class, InputStream.class, new AttachmentStreamUriLoader.Factory()); registry.append(ChunkedImageUrl.class, InputStream.class, new ChunkedImageUrlLoader.Factory()); registry.append(StickerRemoteUri.class, InputStream.class, new StickerRemoteUriLoader.Factory()); registry.append(BlurHash.class, BlurHash.class, new BlurHashModelLoader.Factory()); registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); }
Example #2
Source File: BitmapUtil.java From Silence with GNU General Public License v3.0 | 6 votes |
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(); }
Example #3
Source File: BitmapUtil.java From Silence with GNU General Public License v3.0 | 4 votes |
public static <T> byte[] createScaledBytes(Context context, T model, MediaConstraints constraints) throws BitmapDecodingException { CompressFormat compressFormat = CompressFormat.PNG; int quality = 100; int attempts = 0; byte[] bytes; Bitmap scaledBitmap = Downsampler.AT_MOST.decode(getInputStreamForModel(context, model), Glide.get(context).getBitmapPool(), constraints.getImageMaxWidth(context), constraints.getImageMaxHeight(context), DecodeFormat.PREFER_RGB_565); if (scaledBitmap == null) { throw new BitmapDecodingException("Unable to decode image"); } try { do { attempts++; ByteArrayOutputStream baos = new ByteArrayOutputStream(); scaledBitmap.compress(compressFormat, quality, baos); bytes = baos.toByteArray(); Log.w(TAG, "iteration with quality " + quality + "; size " + (bytes.length / 1024) + "kb; attempts " + attempts); compressFormat = CompressFormat.JPEG; if (quality > MAX_COMPRESSION_QUALITY) { quality = MAX_COMPRESSION_QUALITY; } else { quality = quality - COMPRESSION_QUALITY_DECREASE; } } while (bytes.length > constraints.getImageMaxSize(context)); return bytes; } finally { if (scaledBitmap != null) scaledBitmap.recycle(); } }
Example #4
Source File: BitmapRequestBuilder.java From giffun with Apache License 2.0 | 3 votes |
/** * Load images using the given {@link Downsampler}. Replaces any existing image decoder. Defaults to * {@link Downsampler#AT_LEAST}. Will be ignored if the data represented by the model is a video. This replaces any * previous calls to {@link #imageDecoder(ResourceDecoder)} and {@link #decoder(ResourceDecoder)} with default * decoders with the appropriate options set. * * @see #imageDecoder * * @param downsampler The downsampler. * @return This request builder. */ private BitmapRequestBuilder<ModelType, TranscodeType> downsample(Downsampler downsampler) { this.downsampler = downsampler; imageDecoder = new StreamBitmapDecoder(downsampler, bitmapPool, decodeFormat); super.decoder(new ImageVideoBitmapDecoder(imageDecoder, videoDecoder)); return this; }
Example #5
Source File: BitmapRequestBuilder.java From giffun with Apache License 2.0 | 2 votes |
/** * Load images at a size near the size of the target using {@link Downsampler#AT_LEAST}. * * @see #downsample(Downsampler) * * @return This request builder. */ public BitmapRequestBuilder<ModelType, TranscodeType> approximate() { return downsample(Downsampler.AT_LEAST); }
Example #6
Source File: BitmapRequestBuilder.java From giffun with Apache License 2.0 | 2 votes |
/** * Load images at their original size using {@link Downsampler#NONE}. * * @see #downsample(Downsampler) * * @return This request builder. */ public BitmapRequestBuilder<ModelType, TranscodeType> asIs() { return downsample(Downsampler.NONE); }
Example #7
Source File: BitmapRequestBuilder.java From giffun with Apache License 2.0 | 2 votes |
/** * Load images at a size that is at most exactly as big as the target using * {@link Downsampler#AT_MOST}. * * @see #downsample(Downsampler) * * @return This request builder. */ public BitmapRequestBuilder<ModelType, TranscodeType> atMost() { return downsample(Downsampler.AT_MOST); }