|
12 | 12 | import android.graphics.drawable.Drawable; |
13 | 13 | import android.graphics.drawable.PictureDrawable; |
14 | 14 | import android.util.AttributeSet; |
| 15 | +import android.view.View; |
15 | 16 |
|
16 | 17 | import androidx.annotation.DrawableRes; |
17 | 18 | import androidx.annotation.NonNull; |
@@ -144,16 +145,16 @@ private void preDrawShaper(Canvas canvas) { |
144 | 145 | mShapePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); |
145 | 146 | canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mShapePaint, Canvas.ALL_SAVE_FLAG); |
146 | 147 | mShapeResource.setBounds(paddingLeft, paddingTop, width - paddingRight, height - paddingBottom); |
147 | | - float scaleX = 1f; |
148 | | - float scaleY = 1f; |
149 | 148 | if (mShapeResource instanceof PictureDrawable){ |
150 | | - scaleX = mShapeResource.getBounds().width() *1f/mShapeResource.getIntrinsicWidth(); |
151 | | - scaleY = mShapeResource.getBounds().height() *1f/mShapeResource.getIntrinsicHeight(); |
| 149 | + float scaleX = mShapeResource.getBounds().width() *1f/mShapeResource.getIntrinsicWidth(); |
| 150 | + float scaleY = mShapeResource.getBounds().height() *1f/mShapeResource.getIntrinsicHeight(); |
| 151 | + canvas.translate(mShapeResource.getBounds().left, mShapeResource.getBounds().top); |
152 | 152 | canvas.scale(scaleX,scaleY); |
153 | | - } |
154 | | - mShapeResource.draw(canvas); |
155 | | - if (mShapeResource instanceof PictureDrawable){ |
| 153 | + canvas.drawPicture(((PictureDrawable) mShapeResource).getPicture()); |
156 | 154 | canvas.scale(1/scaleX,1/scaleY); |
| 155 | + canvas.translate(-mShapeResource.getBounds().left,- mShapeResource.getBounds().top); |
| 156 | + }else { |
| 157 | + mShapeResource.draw(canvas); |
157 | 158 | } |
158 | 159 | isDrawShapeClear = true; |
159 | 160 | } |
@@ -279,16 +280,16 @@ private void drawShape(Canvas canvas) { |
279 | 280 | mShapePaint.setXfermode(null); |
280 | 281 | canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mShapePaint, Canvas.ALL_SAVE_FLAG); |
281 | 282 | mShapeResource.setBounds(left, top, right, bottom); |
282 | | - float scaleX = 1f; |
283 | | - float scaleY = 1f; |
284 | 283 | if (mShapeResource instanceof PictureDrawable){ |
285 | | - scaleX = mShapeResource.getBounds().width() *1f/mShapeResource.getIntrinsicWidth(); |
286 | | - scaleY = mShapeResource.getBounds().height() *1f/mShapeResource.getIntrinsicHeight(); |
| 284 | + float scaleX = mShapeResource.getBounds().width() *1f/mShapeResource.getIntrinsicWidth(); |
| 285 | + float scaleY = mShapeResource.getBounds().height() *1f/mShapeResource.getIntrinsicHeight(); |
| 286 | + canvas.translate(mShapeResource.getBounds().left, mShapeResource.getBounds().top); |
287 | 287 | canvas.scale(scaleX,scaleY); |
288 | | - } |
289 | | - mShapeResource.draw(canvas); |
290 | | - if (mShapeResource instanceof PictureDrawable){ |
| 288 | + canvas.drawPicture(((PictureDrawable) mShapeResource).getPicture()); |
291 | 289 | canvas.scale(1/scaleX,1/scaleY); |
| 290 | + canvas.translate(-mShapeResource.getBounds().left,- mShapeResource.getBounds().top); |
| 291 | + }else { |
| 292 | + mShapeResource.draw(canvas); |
292 | 293 | } |
293 | 294 | } |
294 | 295 | mShapePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); |
|
0 commit comments