下面列出了com.bumptech.glide.load.Options#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("EmptyCatchBlock")
@Override
public boolean encode(@NonNull Resource<Bitmap> data, @NonNull File file, @NonNull Options options) {
Log.i(TAG, "Encrypted resource encoder running: " + file.toString());
Bitmap bitmap = data.get();
Bitmap.CompressFormat format = getFormat(bitmap, options);
int quality = options.get(BitmapEncoder.COMPRESSION_QUALITY);
try (OutputStream os = createEncryptedOutputStream(secret, file)) {
bitmap.compress(format, quality, os);
os.close();
return true;
} catch (IOException e) {
Log.w(TAG, e);
return false;
}
}
@NonNull
private Bitmap.Config getDecodeFormat(@Nullable Options options) {
DecodeFormat decodeFormat = options == null ? null : options.get(GifOptions.DECODE_FORMAT);
if (decodeFormat == null) {
return Bitmap.Config.ARGB_8888;
}
switch (decodeFormat) {
case PREFER_RGB_565:
return Bitmap.Config.RGB_565;
case PREFER_ARGB_8888:
default:
return Bitmap.Config.ARGB_8888;
}
}
private void prepareSvg(@NonNull Resource<SVG> toTranscode, @Nullable Options options) {
if (!(toTranscode instanceof SvgResource)) {
return;
}
DownsampleStrategy strategy =
options == null ? null : options.get(DownsampleStrategy.OPTION);
if (strategy != null) {
float scaleFactor = strategy.getScaleFactor(
Math.round(toTranscode.get().getDocumentWidth()),
Math.round(toTranscode.get().getDocumentHeight()),
((SvgResource) toTranscode).getWidth(),
((SvgResource) toTranscode).getHeight()
);
SvgUtils.scaleDocumentSize(toTranscode.get(), scaleFactor);
}
}
private Bitmap.CompressFormat getFormat(Bitmap bitmap, Options options) {
Bitmap.CompressFormat format = options.get(BitmapEncoder.COMPRESSION_FORMAT);
if (format != null) {
return format;
} else if (bitmap.hasAlpha()) {
return Bitmap.CompressFormat.PNG;
} else {
return Bitmap.CompressFormat.JPEG;
}
}
@Override
public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) {
return (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_WEBP_DECODER) && WebPParser.isAWebP(new ByteBufferReader(source)))
|| (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER) && APNGParser.isAPNG(new ByteBufferReader(source)))
|| (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_GIF_DECODER) && GifParser.isGif(new ByteBufferReader(source)));
}
@Override
public boolean handles(@NonNull InputStream source, @NonNull Options options) {
return (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_WEBP_DECODER) && WebPParser.isAWebP(new StreamReader(source)))
|| (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER) && APNGParser.isAPNG(new StreamReader(source)))
|| (!options.get(AnimationDecoderOption.DISABLE_ANIMATION_GIF_DECODER) && GifParser.isGif(new StreamReader(source)));
}