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);