glide-image preprocessing (fillet, Gaussian blur, etc.)

Source: Internet
Author: User
Preface:

I have already explained how to display pictures in a simple way, but sometimes there are a lot of special needs in the project, such as fillet processing, circular picture, Gaussian blur, etc., Glide provides the method can be very good processing, next we introduce Glide Series Catalogue 1.glide-Getting Started tutorial 2.glide-taking up bitmaps and loading animations 3.glide-loading local pictures 4.glide-loading gif 5.glide-binding lifecycle 6.glide-memory cache with disk cache 7. glide-Modules Custom Glide 8.glide-Custom cache 9.glide-image compression 10.glide-picture preprocessing (fillet, Gaussian blur, etc.) 11.glide-picture clipping (scaletype) 12.glide-Source Detailed 1. Create a class inheritance Bitmaptransformation

two methods need to be implemented, in which the transform method can get the bitmap object, this is the place to do the image processing

Public  class Cornerstransform extends Bitmaptransformation {

        @Override
        protected Bitmap transform ( Bitmappool Pool, Bitmap totransform, int outwidth, int outheight) {
            //todo
        }



        @Override public
        String GetId () {
           //todo
        }
}
2. Use

you can show the processed picture by calling the Transform method

Glide.with (this). Load (URL). Transform (New Cornerstransform ()). into (IV1);
3. Example (fillet processing) 3.1 Custom Transformation
public class Cornerstransform extends Bitmaptransformation {private float radius;
        Public Cornerstransform (Context context) {super (context);
    RADIUS = 10;
        } public Cornerstransform (context context, float radius) {super (context);
    This.radius = radius;
        } @Override protected Bitmap transform (Bitmappool pool, Bitmap totransform, int outwidth, int outheight) {
    Return Cornerscrop (pool, totransform);

        } private Bitmap Cornerscrop (Bitmappool pool, Bitmap source) {if (source = = null) return null;
        Bitmap result = Pool.get (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8888); if (result = = null) {result = Bitmap.createbitmap (Source.getwidth (), Source.getheight (), Bitmap.Config.ARGB_8
        888);
        Canvas canvas = new canvas (result);
        Paint paint = new paint (); Paint.setshader (new Bitmapshader (source, BitmapShader.TileMode.CLAMP, Bitmapshader.
        Tilemode.clamp));
        Paint.setantialias (TRUE);
        RECTF RECTF = new RECTF (0f, 0f, Source.getwidth (), Source.getheight ());
        Canvas.drawroundrect (RECTF, radius, radius, paint);
    return result;
    } @Override Public String getId () {return getclass (). GetName ();
 }
}
3.2 Use
Glide.with (this). Load (URL). Transform (new Cornerstransform (this,50)). into (IV1);

The effect is as follows:

4. Use multiple transform

The transform method is not supported multiple calls, if you call two times, then the second time will override the first effect

But he has an overloaded method that can pass in multiple objects so that an incoming deformer can take effect

Glide.with (this). Load (URL). Transform (new Circletransform (this), New Cornerstransform (this,50)). into (IV1);
5. Three-party library

If you feel that your custom transform is difficult, or if you want to learn about other people's image processing methods, you can try this tripartite library on GitHub

Glide transformations

Https://github.com/wasabeef/glide-transformations

effects (support rounded corners, Gaussian blur, etc.)

Top Articles glide-compression glide-memory cache vs. disk cache glide-Custom Cache glide-Getting Started Tutorial okhttputils Ultimate Package Facebook launch debug Artifact Android Code optimization Tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.