Android ámöööööööööööö2 ~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Source: Internet
Author: User

Android ámöööööööööööö2 ~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ǰ n £°

Äcaç° íø É Ï Ó ° U à À Ç ² Ç çí ¼ µ µá £ £;{github É Ï ²?» please ************************************************* Ó Github É Ï µäî äö ö± ½ óó {£?? Ø ± ¸ ¼ Ä ä£;%%%%%%%%% ******************************************************* mr. öquímālömāmāmāmāmāmāmāmāmāmāmāmāmāmāmāmān.


Ô ¤ ± ¸ öª £ £°

Xfermode ½ ééü £°

Ï Â Ã Ê çandroid apidemoà {µää ° Xfermodes {± {µà {£%%%^§ *í {£


Xfermode ó~~~ö×óà £;*á~~~~~â £° <symbol · blank "http://www.bkjia.com/kf/ware/vc/" target = "_ blank" class = "keylink "> vcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ =" brush: java; "> public classXfermodeextends Objectjava. lang. object? Android. graphics. XfermodeKnown Direct SubclassesAvoidXfermode, PixelXorXfermode, porterduxfermode

AvoidXfermodeÖ~~~rá~~» Ö ön ~é «° íè ~£ç çöö~paint ± Ü ~â ~ú» guímo (» ò Õ Ö ö» Ú úë üé Ï Ã æ» Í í¼) £.

PixelXorXfermode Μ± ¸ ² Ç çadeonó {µän {é «{± £ *****************************************************» %² %× %%%£

Porterduxfermode â Ç 正ò» ö öç?£çor=*****» ä£;;%%%%%%%%%%%%%%%%%%% ******************** ~~~~órí~añ° {************************************************* painted Paint È ç° Ó Ò ñó µ µäcanvas Í Ï {n ~o ~~~»» £


É Ï Ã æ Í ¼ ¬ Ö öööï Ê µ % ******************************************************

1. PorterDuff. Mode. CLEAR

Ë Ö» Ö öæ ²» ámááchi» µ½» ² É Ï £.
2. PorterDuff. Mode. SRC

Zookeeper ********************************************
3. PorterDuff. Mode. DST

Please refer to zookeeper ~~â ²» ~ö~í ~~~~~
4. PorterDuff. Mode. SRC_OVER

Please refer to the following link for more information:
5. PorterDuff. Mode. DST_OVER

É Ï Â ² ã Â ¼ £ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6. PorterDuff. Mode. SRC_IN

{0} {0} {0} {0} {0} {0}
7. PorterDuff. Mode. DST_IN

{0} {0} {0} {0} {0}
8. PorterDuff. Mode. SRC_OUT

{0} {0} {0} {0}
9. PorterDuff. Mode. DST_OUT

{0} {0} {0} {0}
10. PorterDuff. Mode. SRC_ATOP

{0} {0} {0}
11. PorterDuff. Mode. DST_ATOP

{*************************************
12. PorterDuff. Mode. XOR

Please refer to» £° é £ ****************************************************************
13. PorterDuff. Mode. DARKEN

{0} {0} {0} {0} {0}
14. PorterDuff. Mode. LIGHTEN

{0} {0} {0} {0 «
15. PorterDuff. Mode. MULTIPLY

{0} {0 «
16. PorterDuff. Mode. SCREEN

{0} {0} {0} {0} {0} {0} {0 «


Ábaromantâ ábaréé Ï µ % ¶ μ ã È À '{µöµúram»» ööô ² Ç çí?æ Ö öö × {??

Guí⣰



~È then '{â }» ~~~~~~~~â

private ImageView mImg;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mImg = (ImageView) findViewById(R.id.img);//»ñµÃimageviewÖÐÉèÖõÄͼƬBitmapDrawable drawable = (BitmapDrawable) mImg.getDrawable();Bitmap bmp = drawable.getBitmap();//»ñµÃͼƬµÄ¿í£¬²¢´´½¨½á¹ûbitmapint width = bmp.getWidth();Bitmap resultBmp = Bitmap.createBitmap(width, width,Bitmap.Config.ARGB_8888);Paint paint = new Paint();Canvas canvas = new Canvas(resultBmp);//»Ô²canvas.drawCircle(width / 2, width / 2, width / 2, paint);paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));// Ñ¡Ôñ½»¼¯È¥ÉϲãͼƬcanvas.drawBitmap(bmp, 0, 0, paint);mImg.setImageBitmap(resultBmp);bmp.recycle();}

Íâ ¹ ý Ô Ð ********************************************


''?********************************************************************** Äü µ¼ öâ OutOfMomery ?=£;%%%%% ****************** **********************************? required bytes ImageView maid» N. µomí ************************************************************ Ó Ô Ø µä äú' {£ä äã» á. ¢ Ö ö¿ éäü» áö öï öò £ £. ×ögou»  ¸ ä±ä¡ £.


private static final String TAG = "RoundImage";private ImageView mImg;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mImg = (ImageView) findViewById(R.id.img);// ²Ã¼ôͼƬBitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;BitmapFactory.decodeResource(getResources(), R.drawable.avatar, options);Log.d(TAG, "original outwidth: " + options.outWidth);// ´Ë¿í¶ÈÊÇÄ¿±êImageViewÏ£ÍûµÄ´óС£¬Äã¿ÉÒÔ×Ô¶¨ÒåImageView£¬È»ºó»ñµÃImageViewµÄ¿í¶È¡£int dstWidth = 150;// ÎÒÃÇÐèÒª¼ÓÔØµÄͼƬ¿ÉÄܴܺó£¬ÎÒÃÇÏȶÔÔÓеÄͼƬ½øÐвüôint sampleSize = calculateInSampleSize(options, dstWidth, dstWidth);options.inSampleSize = sampleSize;options.inJustDecodeBounds = false;Log.d(TAG, "sample size: " + sampleSize);Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.avatar, options);// »æÖÆÍ¼Æ¬Bitmap resultBmp = Bitmap.createBitmap(dstWidth, dstWidth,Bitmap.Config.ARGB_8888);Paint paint = new Paint();paint.setAntiAlias(true);Canvas canvas = new Canvas(resultBmp);// »Ô²canvas.drawCircle(dstWidth / 2, dstWidth / 2, dstWidth / 2, paint);// Ñ¡Ôñ½»¼¯È¥ÉϲãͼƬpaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));canvas.drawBitmap(bmp, new Rect(0, 0, bmp.getWidth(), bmp.getWidth()),new Rect(0, 0, dstWidth, dstWidth), paint);mImg.setImageBitmap(resultBmp);bmp.recycle();}private int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight) {// Raw height and width of imagefinal int height = options.outHeight;final int width = options.outWidth;int inSampleSize = 1;if (height > reqHeight || width > reqWidth) {final int halfHeight = height / 2;final int halfWidth = width / 2;// Calculate the largest inSampleSize value that is a power of 2 and// keeps both// height and width larger than the requested height and width.while ((halfHeight / inSampleSize) > reqHeight&& (halfWidth / inSampleSize) > reqWidth) {inSampleSize *= 2;}}return inSampleSize;}

Ô À 'taobao' then» Â Ð § £ £°


É Ï Ã æ ámámámáë» öööö £ ££ ü à? ¥ó Å» £ ¡£.


~× ~~~~~~~~~~Á~~~~~â» ~öà BitmapShader

Ò Ó µ µä *****************************************************************

Public BitmapShader (Bitmap bitmap, Shader. TileMode tileX, Shader. TileMode tileY)

μ Ó Õ â ö öö · rírá'² úéúégou» ö ö» Ó ö Ò» ¸ öî» Í ¼ äööööööè Æ £m. Shader £;£.

Bitmap ~úäööè Æ ä äú~~~ó ~µä~» í ~

TileX The tiling mode for x to draw the bitmap in. ~úres» Í É X. ~~~~»?

TileY The tiling mode for y to draw the bitmap in. Ú úres» Í É Ï Y · ½ Ï ò »?

TileMode £° £°{» %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CLAMP £° çäöööè ¾ ³ ~~~~~ö~~~~± ç ço ~~~§ £;» á § äú± {%%%%%%é «%£

REPEAT £° á Ï ° °í × Ý Ï %%µäöø ~~~~~***********************************************

MIRROR £° á Ï ° °í × Ý Ï µ µäööø ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{{° írepeatöø comment '· Zookeeper 2» N. £;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Öª µà Õ â Ö öô áí° ózant?ç Ç £ ú?

public class CircleImageView extends ImageView {private static final String TAG = CircleImageView.class.getSimpleName();private Paint mBitmapPaint = new Paint();private int mRadius;public CircleImageView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}public CircleImageView(Context context, AttributeSet attrs) {super(context, attrs);init();}public CircleImageView(Context context) {super(context);init();}private void init() {BitmapDrawable drawable = (BitmapDrawable) getDrawable();if (drawable == null) {Log.i(TAG, "drawable: null");return;}Bitmap bmp = drawable.getBitmap();BitmapShader shader = new BitmapShader(bmp, TileMode.CLAMP,TileMode.CLAMP);mBitmapPaint.setShader(shader);mBitmapPaint.setAntiAlias(true);invalidate();}@Overrideprotected void onDraw(Canvas canvas) {if (getDrawable() == null) {return;}mRadius = Math.min(getWidth()/2, getHeight()/2);canvas.drawCircle(getWidth() / 2, getHeight() / 2, mRadius,mBitmapPaint);}}

Ç ç²» Ç çí ~~~µ¥µä

Yangá¹ Î ****************************************** * zookeeper has been transferred to µäúâ £ £;ä äõ  µämááám² and ~~~öö» · *********************************** ý µäúâ ë %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


public class CircleImageView extends ImageView {    private static final ScaleType SCALE_TYPE = ScaleType.CENTER_CROP;    private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;    private static final int COLORDRAWABLE_DIMENSION = 1;    private static final int DEFAULT_BORDER_WIDTH = 0;    private static final int DEFAULT_BORDER_COLOR = Color.BLACK;    private final RectF mDrawableRect = new RectF();    private final RectF mBorderRect = new RectF();    private final Matrix mShaderMatrix = new Matrix();    private final Paint mBitmapPaint = new Paint();    private final Paint mBorderPaint = new Paint();    private int mBorderColor = DEFAULT_BORDER_COLOR;    private int mBorderWidth = DEFAULT_BORDER_WIDTH;    private Bitmap mBitmap;    private BitmapShader mBitmapShader;    private int mBitmapWidth;    private int mBitmapHeight;    private float mDrawableRadius;    private float mBorderRadius;    private boolean mReady;    private boolean mSetupPending;    public CircleImageView(Context context) {        super(context);        init();    }    public CircleImageView(Context context, AttributeSet attrs) {        this(context, attrs, 0);    }    public CircleImageView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);        mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);        mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);        a.recycle();        init();    }    private void init() {        super.setScaleType(SCALE_TYPE);        mReady = true;        if (mSetupPending) {            setup();            mSetupPending = false;        }    }    @Override    public ScaleType getScaleType() {        return SCALE_TYPE;    }    @Override    public void setScaleType(ScaleType scaleType) {        if (scaleType != SCALE_TYPE) {            throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));        }    }    @Override    protected void onDraw(Canvas canvas) {        if (getDrawable() == null) {            return;        }        canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint);        if (mBorderWidth != 0) {            canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, mBorderPaint);        }    }    @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        super.onSizeChanged(w, h, oldw, oldh);        setup();    }    public int getBorderColor() {        return mBorderColor;    }    public void setBorderColor(int borderColor) {        if (borderColor == mBorderColor) {            return;        }        mBorderColor = borderColor;        mBorderPaint.setColor(mBorderColor);        invalidate();    }    public int getBorderWidth() {        return mBorderWidth;    }    public void setBorderWidth(int borderWidth) {        if (borderWidth == mBorderWidth) {            return;        }        mBorderWidth = borderWidth;        setup();    }    @Override    public void setImageBitmap(Bitmap bm) {        super.setImageBitmap(bm);        mBitmap = bm;        setup();    }    @Override    public void setImageDrawable(Drawable drawable) {        super.setImageDrawable(drawable);        mBitmap = getBitmapFromDrawable(drawable);        setup();    }    @Override    public void setImageResource(int resId) {        super.setImageResource(resId);        mBitmap = getBitmapFromDrawable(getDrawable());        setup();    }    @Override    public void setImageURI(Uri uri) {        super.setImageURI(uri);        mBitmap = getBitmapFromDrawable(getDrawable());        setup();    }    private Bitmap getBitmapFromDrawable(Drawable drawable) {        if (drawable == null) {            return null;        }        if (drawable instanceof BitmapDrawable) {            return ((BitmapDrawable) drawable).getBitmap();        }        try {            Bitmap bitmap;            if (drawable instanceof ColorDrawable) {                bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);            } else {                bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);            }            Canvas canvas = new Canvas(bitmap);            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());            drawable.draw(canvas);            return bitmap;        } catch (OutOfMemoryError e) {            return null;        }    }    private void setup() {        if (!mReady) {            mSetupPending = true;            return;        }        if (mBitmap == null) {            return;        }        mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);        mBitmapPaint.setAntiAlias(true);        mBitmapPaint.setShader(mBitmapShader);        mBorderPaint.setStyle(Paint.Style.STROKE);        mBorderPaint.setAntiAlias(true);        mBorderPaint.setColor(mBorderColor);        mBorderPaint.setStrokeWidth(mBorderWidth);        mBitmapHeight = mBitmap.getHeight();        mBitmapWidth = mBitmap.getWidth();        mBorderRect.set(0, 0, getWidth(), getHeight());        mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);        mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);        mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);        updateShaderMatrix();        invalidate();    }    private void updateShaderMatrix() {        float scale;        float dx = 0;        float dy = 0;        mShaderMatrix.set(null);        if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {            scale = mDrawableRect.height() / (float) mBitmapHeight;            dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;        } else {            scale = mDrawableRect.width() / (float) mBitmapWidth;            dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;        }        mShaderMatrix.setScale(scale, scale);        mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);        mBitmapShader.setLocalMatrix(mShaderMatrix);    }}

2. ¹ ä ää» μ ã É Ï µ %% ********************************************************** * ÷ äø £;{â ö öö Ì Á â áô ~~~~~~{{° É {£.


{0}

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.