Android Magnifier shapedrawable magical Sharing _android

Source: Internet
Author: User

First, the shape of the painting can be specified when the shapedrawable is constructed,

Second, you can use Shape.getpaint (). Setshader (); Specify Shader,shader can accept a picture and matrix

So the problem is solved smoothly:

Specifically implemented as follows:
[Java]

Copy Code code as follows:

float scale = 1.2f;

int cx = 224;
int cy = 357;
int r = 200;

Specifies that the shape creates a shapedrawable
Shapedrawable shape=new shapedrawable (New OvalShape ());
Bitmap BM = Bitmapfactory.decoderesource (Getresources (), R.DRAWABLE.BG1);
Bitmapshader bs = new Bitmapshader (BM, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Matrix M = new Matrix ();
M.settranslate (R-CX, r-cy);
M.postscale (scale, scale);
Bs.setlocalmatrix (m); Graphical transformations can be implemented here, including region designation

Set shader for Shapedrawable
Shape.getpaint (). Setshader (BS);

Specify the target position to be painted
Shape.setbounds ((int) (Cx-r*scale), (int) (Cy-r*scale), (int) (Cx+r*scale), (int) (Cy+r*scale));
Canvas.drawbitmap (BM, 0, 0, NULL);
Shape.draw (canvas);

float scale = 1.2f;

int cx = 224;
int cy = 357;
int r = 200;


Specifies that the shape creates a shapedrawable
Shapedrawable shape=new shapedrawable (New OvalShape ());
Bitmap BM = Bitmapfactory.decoderesource (Getresources (), R.DRAWABLE.BG1);
Bitmapshader bs = new Bitmapshader (BM, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

Matrix M = new Matrix ();
M.settranslate (R-CX, r-cy);
M.postscale (scale, scale);
Bs.setlocalmatrix (m); Graphical transformations can be implemented here, including region designation

Set shader for Shapedrawable
Shape.getpaint (). Setshader (BS);

Specify the target position to be painted
Shape.setbounds ((int) (Cx-r*scale), (int) (Cy-r*scale), (int) (Cx+r*scale), (int) (Cy+r*scale));
Canvas.drawbitmap (BM, 0, 0, NULL);
Shape.draw (canvas);

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.