High imitation QQ Avatar screenshot, high imitation Avatar screenshot

Source: Internet
Author: User

High imitation QQ Avatar screenshot, high imitation Avatar screenshot

After spending half a day, I sorted out the imitation QQ Avatar Interception Method and made a demo for your reference, basically, I achieved the general effect on the qq information interface (including transparent background, sliding title bar display, drop-down and hide). Let's first look at the effect:










Supported functions:

1. Select the cropped image to support gesture zoom-in and zoom-out (including double-click zoom-in and zoom-out );

2. Determine the image edge, that is, the cropping area will not exceed the image edge;

Principle:

A rewritten RelativeLayout contains two layers of views. The lower layer is the rewritten scaled ImageView that is used to place the cropped image. The upper layer of the ImageView is a custom View, A white circle drawn through onDraw represents the cropping area. In fact, in this demo, When you click "OK", the cropped area is a square area, for example:


The bitmap method of the cropped square (mHorizontalPadding is the distance from the cropping area to the left and right of the screen, and mVerticalPadding is the distance between the cropping area and the screen ):

Bitmap bitmap = Bitmap. createBitmap (getWidth (), getHeight (), Bitmap. config. ARGB_8888); Canvas canvas = new Canvas (bitmap); draw (canvas); // If the crop is a square area, the getCircleBitmap method can be removed to return getCircleBitmap (Bitmap. createBitmap (bitmap, mHorizontalPadding, mVerticalPadding, getWidth ()-2 * mHorizontalPadding, getWidth ()-2 * mHorizontalPadding ));

Only convert the generated square bitmap to a circular bitmap:

/*** Convert a square bitmap to a circular bitmap * @ param bitmap * @ return */private Bitmap getCircleBitmap (Bitmap bitmap) {Bitmap output = Bitmap. createBitmap (bitmap. getWidth (), bitmap. getHeight (), Config. ARGB_8888); Canvas canvas = new Canvas (output); final int color = 0xff0000242; final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight (); Paint paint = new Paint (); paint. setAntiAlias (true); canvas. drawARGB (0, 0, 0, 0); paint. setColor (color); int x = bitmap. getWidth (); canvas. drawCircle (x/2, x/2, x/2, paint); paint. setXfermode (new porterduduxfermode (Mode. SRC_IN); canvas. drawBitmap (bitmap, rect, rect, paint); return output ;}

One Variable in ClipImageLayout is mHorizontalPadding, which is the distance between the Circular Boundary of the cropping area and the edge of the screen. The larger the value, the smaller the cropping area. The larger the contrast, the greater the value (of course, not less than 0 );

Note that:

Add

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)

To prevent the height of the notification bar of different mobile phones from affecting the accuracy of determining whether the cropping area is beyond the image range;

In addition, the cropping interface converts the selected image to bitmap for display. If the resource is too large, memory overflow may occur. Therefore, one step of compression is required:

Bitmap bitmap=ImageTools.convertToBitmap(path, 600,600);

If you want to crop a square Avatar, you can change the border of the cropping area on the cropping interface to a square:

// Square border // canvas. drawRect (mHorizontalPadding, mVerticalPadding, getWidth ()-mHorizontalPadding, getHeight ()-mVerticalPadding, mPaint); // canvas with a circular border. drawCircle (getWidth ()/2, getHeight ()/2, getWidth ()/2-mHorizontalPadding, mPaint );

Remove the bitmap method generated after cropping to convert it into a circular bitmap. The comments in the Code are also very clear.


Source code on: http://download.csdn.net/detail/baiyuliang2013/8467647





Related Article

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.