Android set fillet picture implementation code _android

Source: Internet
Author: User
Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/layout"
android:orientation= "Vertical"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
>
</LinearLayout>
Package Com.test.demo;

Import android.app.Activity;
Import Android.graphics.Bitmap;
Import Android.graphics.Bitmap.Config;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import Android.graphics.PorterDuff.Mode;
Import Android.graphics.PorterDuffXfermode;
Import Android.graphics.Rect;
Import Android.graphics.RectF;
Import android.graphics.drawable.BitmapDrawable;
Import android.graphics.drawable.Drawable;
Import Android.os.Bundle;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;

public class MyActivity extends activity {
/** called the activity is a. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

drawable drawable = Getresources (). getdrawable (r.drawable.bg);
Bitmapdrawable bitmapdrawable = (bitmapdrawable) drawable;
Bitmap Bitmap = Bitmapdrawable.getbitmap ();

LinearLayout layout = (linearlayout) Findviewbyid (r.id.layout);
drawable drawable = Getresources (). getdrawable (r.drawable.bg);
Bitmapdrawable bitmapdrawable = (bitmapdrawable) drawable;
Bitmap Bitmap = Bitmapdrawable.getbitmap ();

bitmapdrawable bbb = new Bitmapdrawable (Toroundcorner (bitmap, 30));
Layout.setbackgrounddrawable (BBB);
ImageView ImageView = (imageview) Findviewbyid (r.id.imgshow);
Imageview.setimagebitmap (Myactivity.getroundedcornerbitmap (bitmap));
Imageview.setimagebitmap (Myactivity.toroundcorner (Bitmap, 20));
}
public static Bitmap Toroundcorner (Bitmap Bitmap, int pixels) {

Bitmap output = Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), config.argb_8888);
Canvas Canvas = new Canvas (output);

final int color = 0xff424242;
Final Paint Paint = new Paint ();
Final Rect Rect = new Rect (0, 0, bitmap.getwidth (), Bitmap.getheight ());
Final RECTF RECTF = new RECTF (rect);
Final float roundpx = pixels;

Paint.setantialias (TRUE);
Canvas.drawargb (0, 0, 0, 0);
Paint.setcolor (color);
Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint);

Paint.setxfermode (New Porterduffxfermode (mode.src_in));
Canvas.drawbitmap (Bitmap, rect, rect, paint);

return output;
}
}

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.