tencent cloud

Cloud Infinite

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Product Overview
Product Strengths
Use Cases
Feature Overview
Regions and Domains
Specifications and Limits
Billing
Billing Overview
Billing Mode
Billable Items
Free Tier
Payment Overdue
Viewing Bill Details
FAQs
Getting Started
Registering and Logging In
Bind Bucket
Uploading and Processing File
Downloading and Deleting Images
Unbinding Buckets
Using CI via COS
Features
Image Processing
Media Processing
Content Moderation
AI Content Recognition
File Processing
Smart Voice
File processing
User Guide
Overview
Bucket Management
Smart Toolbox
Job and Workflow
Data Monitoring
Usage statistics
Use Cases
Copyright Protection Solutions
Image Processing Practices
Working with API Authorization Policies
Workflow Practices
API Documentation
API Overview
Structure
Common Request Headers
Common Response Headers
Activate Vast Service
Image Processing
AI-Based Content Recognition
Smart Audio
Media Processing
Content Moderation
Document Processing
File Processing
Job and Workflow
Cloud Virus Detection
Error Codes
Request Signature
SDK Documentation
SDK Overview
Android SDK
iOS SDK
COS Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Go SDK
COS iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
Mini Program SDK
Personal Information Protection Policy for SDK
Security and Compliance
Permission ‍Management
FAQs
Basic Settings
Document Processing
Media Processing
Content Recognition
Smart Audio
Agreements
Service Level Agreement
Contact Us
Glossary

Loading Image with Glide

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-03-04 10:30:23
This document describes how to load images with Glide.

Installing Glide

implementation 'com.github.bumptech.glide:glide:version'

Basic Image Processing

Use Glide and CI together to perform basic image processing operations (except TPG and AVIF features).
1. Construct a CIImageLoadRequest by using CloudInfinite and CITransformation.
CloudInfinite cloudInfinite = new CloudInfinite();
CITransformation transform = new CITransformation();
transform.thumbnailByScale(50).iradius(60);
CIImageLoadRequest request = cloudInfinite.requestWithBaseUrlSync(url, transform);
2. Get the URL through the obtained CIImageLoadRequest and use Glide to load it.
Glide.with(activity).load(request.getUrl().toString()).into(imageview);

Using CI's Glide Feature

Install the cloud-infinite-glide SDK and glide:compiler.
implementation 'com.qcloud.cos:cloud-infinite-glide:1.2.1'
annotationProcessor 'com.github.bumptech.glide:compiler:version'
Register relevant decoders and loaders through AppGlideModule to implement corresponding features.
// Register the custom `GlideModule`
// You should create this class to register `CIImageRequestModelLoader` and `ImageAveDecoder`.<br>
// If you develop class libraries, you can inherit `LibraryGlideModule` to create a similar registration class.
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, Registry registry) {
// Register a loader that supports `CIImageLoadRequest`
registry.prepend(CIImageLoadRequest.class, InputStream.class, new CIImageRequestModelLoader.Factory());

// Register the main color decoder
registry.prepend(InputStream.class, Bitmap.class, new ImageAveDecoder(glide.getBitmapPool()));
}
}

Preloading with image main color

// Register the main color decoder in `AppGlideModule` first
registry.prepend(InputStream.class, Bitmap.class, new ImageAveDecoder(glide.getBitmapPool()));

// Use Glide's thumbnail to preload the main color
Glide.with(context)
.load(imageUrl)
.thumbnail(CloudInfiniteGlide.getImageAveThumbnail(context, imageUrl))
.into(imageview);

Directly loading CIImageLoadRequest

Currently, this method is only used for the case where the header transfers the target image format during format conversion.
registry.prepend(CIImageLoadRequest.class, InputStream.class, new CIImageRequestModelLoader.Factory());

Using CI's TPG Feature

Install the TPG SDK and glide:compiler.
implementation 'com.qcloud.cos:tpg:1.3.2'
annotationProcessor 'com.github.bumptech.glide:compiler:version'
Register relevant decoders through AppGlideModule to implement corresponding features.
// Register the custom `GlideModule`
// You should create this class to register `TpgDecoder` and `ByteBufferTpgGifDecoder`.<br>
// If you develop class libraries, you can inherit `LibraryGlideModule` to create a similar registration class.
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, Registry registry) {
/*------------------Decoder start-------------------------*/
// Register the static TPG image decoder
registry.prepend(InputStream.class, Bitmap.class, new TpgDecoder(glide.getBitmapPool()));
// Register the animated TPG image decoder
ByteBufferTpgGifDecoder byteBufferTpgGifDecoder = new ByteBufferTpgGifDecoder(context, glide.getBitmapPool(), glide.getArrayPool());
registry.prepend(InputStream.class, GifDrawable.class, new StreamTpgGifDecoder(byteBufferTpgGifDecoder));
registry.prepend(ByteBuffer.class, GifDrawable.class, byteBufferTpgGifDecoder);
/*------------------Decoder end-------------------------*/
}
}

Loading static TPG image

registry.prepend(InputStream.class, Bitmap.class, new TpgDecoder(glide.getBitmapPool()));

Loading animated TPG image

ByteBufferTpgGifDecoder byteBufferTpgGifDecoder = new ByteBufferTpgGifDecoder(context, glide.getBitmapPool(), glide.getArrayPool());
registry.prepend(InputStream.class, GifDrawable.class, new StreamTpgGifDecoder(byteBufferTpgGifDecoder));
registry.prepend(ByteBuffer.class, GifDrawable.class, byteBufferTpgGifDecoder);

Using CI's AVIF Feature

Install the AVIF SDK and glide:compiler.
implementation 'com.qcloud.cos:avif:1.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:version'
Register relevant decoders through AppGlideModule to implement corresponding features.
// Register the custom `GlideModule`
// You should create this class to register relevant decoders.<br>
// If you develop class libraries, you can inherit `LibraryGlideModule` to create a similar registration class.
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, Registry registry) {
/*------------------Decoder start-------------------------*/
// Register the static AVIF image decoder
registry.prepend(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, new StreamAvifDecoder(glide.getBitmapPool(), glide.getArrayPool()));
registry.prepend(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, new ByteBufferAvifDecoder(glide.getBitmapPool()));
// Register the animated AVIF image decoder
registry.prepend(InputStream.class, AvifSequenceDrawable.class, new StreamAvifSequenceDecoder(glide.getBitmapPool(), glide.getArrayPool()));
registry.prepend(ByteBuffer.class, AvifSequenceDrawable.class, new ByteBufferAvifSequenceDecoder(glide.getBitmapPool()));
/*------------------Decoder end-------------------------*/
}
}

Loading static AVIF image

registry.prepend(Registry.BUCKET_BITMAP, InputStream.class, Bitmap.class, new StreamAvifDecoder(glide.getBitmapPool(), glide.getArrayPool()));
registry.prepend(Registry.BUCKET_BITMAP, ByteBuffer.class, Bitmap.class, new ByteBufferAvifDecoder(glide.getBitmapPool()));

Loading animated AVIF image

registry.prepend(InputStream.class, AvifSequenceDrawable.class, new StreamAvifSequenceDecoder(glide.getBitmapPool(), glide.getArrayPool()));
registry.prepend(ByteBuffer.class, AvifSequenceDrawable.class, new ByteBufferAvifSequenceDecoder(glide.getBitmapPool()));

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan