First, you can specify the drawing shape when ShapeDrawable is constructed,
Second, you can use shape. getPaint (). setShader (); to specify the Shader. The shader can accept an image and a matrix.
So the problem is solved smoothly :)
The specific implementation is as follows:
[Java]
Copy codeCode: float scale = 1.2f;
Int cx = 224;
Int cy = 357;
Int r = 200;
// Create a ShapeDrawable with the specified shape
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 transformation can be implemented here, including region designation
// Set Shader for ShapeDrawable
Shape. getPaint (). setShader (bs );
// Specify the target position
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;
// Create a ShapeDrawable with the specified shape
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 transformation can be implemented here, including region designation
// Set Shader for ShapeDrawable
Shape. getPaint (). setShader (bs );
// Specify the target position
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 );