Android if the ImageView do fillet, if the original bitmap with some modified drawable

Source: Internet
Author: User

First on:



Layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:backg Round= "#99CC99" tools:context= ".        Mainactivity "> <imageview android:id=" @+id/img1 "android:layout_centerinparent=" true " Android:layout_width= "50DP" android:layout_height= "50DP" android:adjustviewbounds= "true" Android: Scaletype= "Centerinside" android:src= "@drawable/portrait"/> <imageview android:id= "@+i D/img5 "android:layout_centervertical=" true "android:layout_toleftof=" @id/img1 "Android:layout_margin         right= "20DP" android:layout_width= "50DP" android:layout_height= "50DP" android:adjustviewbounds= "true" Android:scaletype= "Fitxy" android:src= "@drawable/portrait"/> <imageview androi D:id= "@+id/img6 "android:layout_centervertical=" true "android:layout_toleftof=" @id/img5 "Android:layout_marginr        ight= "20DP" android:layout_width= "50DP" android:layout_height= "50DP" android:adjustviewbounds= "true" Android:scaletype= "center" android:src= "@drawable/portrait"/> <imageview androi D:id= "@+id/img4" android:layout_centervertical= "true" android:layout_marginleft= "20DP" android:layout _torightof= "@id/img1" android:layout_width= "50DP" android:layout_height= "50DP" Android:adjustviewboun          Ds= "true" android:scaletype= "Centercrop" android:src= "@drawable/portrait"/> <imageview        Android:id= "@+id/img7" android:layout_centervertical= "true" android:layout_marginleft= "20DP" android:layout_torightof= "@id/img4" android:layout_width= "50DP" android:layout_height= "50DP" Android : Adjustviewbounds= "true"        Android:scaletype= "Fitcenter" android:src= "@drawable/portrait"/> <imageview        Android:id= "@+id/img2" android:layout_marginbottom= "20DP" android:layout_centerhorizontal= "true"        Android:layout_above= "@id/img1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" /> <imageview android:id= "@+id/img3" android:layout_margintop= "20DP" Androi        D:layout_centerhorizontal= "true" android:layout_below= "@id/img1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/></relativelayout>


Let's start by introducing two ways to turn the drawable of resources into bitmap.

The first type:

Bitmap Bmp=bitmapfactory.decoderesource (This.getresources (), r.drawable.portrait);
The second type:

drawable d = this.getresources (). getdrawable (r.drawable.portrait); Bitmap bmp = Drawabletobitmap (d);p ublic static Bitmap drawabletobitmap (drawable drawable) {               Bitmap Bitmap = bitmap.cr Eatebitmap (                                        drawable.getintrinsicwidth (),                                        drawable.getintrinsicheight (),                                        Bitmap.Config.ARGB_8888                                                        );        Canvas canvas = new canvas (bitmap);        Canvas.setbitmap (bitmap);        Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());        Drawable.draw (canvas);        return bitmap;}

How to add bitmap to fillet:

private static RECTF RRBRECTF = new RECTF ();p rivate static Path Rrbrath = new Path ();p rivate static final int rrb_default_ SIZE = 10;public static Bitmap outputbmp (Context ctx, Bitmap src, boolean iscover) {Bitmap v = null;if (iscover) {v = bitm Apfactory.decoderesource (Ctx.getresources (), r.drawable.v);} Else{v = Bitmapfactory.decoderesource (Ctx.getresources (), r.drawable.tv);} Bitmap bmp = Null;int arclength = rrb_default_size;if (src! = null && arclength > 0) {int width = src.getwidth ( ); int height = src.getheight ();//Utils.loge ("width:" + width + "Height:" + height); Bitmap Newbitmap = Bitmap.createbitmap (width, height,bitmap.config.argb_4444); Canvas canvas = new canvas (newbitmap); Rrbrath.reset (); rrbrectf.set (0, 0, width, height);<strong>  Rrbrath.addroundrect (RRBRECTF, arclength, ARCLENGTH,PATH.DIRECTION.CW); Here is the fillet </strong>canvas.clippath (rrbrath), Canvas.drawbitmap (src, 0, 0, new Paint (Paint.anti_alias_flag)); (Newbitmap! = null && v! = null) {int WIDth1 = Newbitmap.getwidth (); int height1 = Newbitmap.getheight (); int width2 = V.getwidth (); int height2 = V.getheight (); BMP = Bitmap.createbitmap (width1 + (WIDTH2/2), height1+ (HEIGHT2/2), Bitmap.Config.ARGB_4444); Bmp.erasecolor (Color.trans PARENT); Canvas CANVAS2 = new canvas (BMP); Canvas2.drawbitmap (newbitmap, 0, 0, new Paint (Paint.anti_alias_flag));<strong>  Canvas2.drawbitmap (V, width1-(WIDTH2/2), height1-(HEIGHT2/2), New Paint (Paint.anti_alias_flag)); Here is the bottom right corner of the picture plus v</strong>newbitmap.recycle (); v.recycle (); return bmp;} Src.recycle ();} return bmp;}


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.