Skip to content

Commit c96d833

Browse files
committed
1,修复svg格式图显示bug
1 parent 26aa775 commit c96d833

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

README-zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ allprojects {
4545

4646
```gradle
4747
dependencies {
48-
implementation 'com.github.FlyJingFish:ShapeImageView:1.5.3'
48+
implementation 'com.github.FlyJingFish:ShapeImageView:1.5.4'
4949
}
5050
```
5151
## 第三步,使用说明

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ allprojects {
4848

4949
```gradle
5050
dependencies {
51-
implementation 'io.github.FlyJingFish:ShapeImageView:1.5.3'
51+
implementation 'io.github.FlyJingFish:ShapeImageView:1.5.4'
5252
}
5353
```
5454
## The third step, instructions for use

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020

2121
PROJ_GROUP=io.github.FlyJingFish
22-
PROJ_VERSION=1.5.3
22+
PROJ_VERSION=1.5.4
2323
PROJ_BASENAME=ShapeImageView
2424
PROJ_WEBSITEURL=https://github.com/FlyJingFish/ShapeImageView
2525
PROJ_VCSURL=https://github.com/FlyJingFish/ShapeImageView.git

library/src/main/java/com/flyjingfish/shapeimageviewlib/AlmightyShapeImageView.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.graphics.drawable.Drawable;
1313
import android.graphics.drawable.PictureDrawable;
1414
import android.util.AttributeSet;
15+
import android.view.View;
1516

1617
import androidx.annotation.DrawableRes;
1718
import androidx.annotation.NonNull;
@@ -144,16 +145,16 @@ private void preDrawShaper(Canvas canvas) {
144145
mShapePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
145146
canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mShapePaint, Canvas.ALL_SAVE_FLAG);
146147
mShapeResource.setBounds(paddingLeft, paddingTop, width - paddingRight, height - paddingBottom);
147-
float scaleX = 1f;
148-
float scaleY = 1f;
149148
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);
152152
canvas.scale(scaleX,scaleY);
153-
}
154-
mShapeResource.draw(canvas);
155-
if (mShapeResource instanceof PictureDrawable){
153+
canvas.drawPicture(((PictureDrawable) mShapeResource).getPicture());
156154
canvas.scale(1/scaleX,1/scaleY);
155+
canvas.translate(-mShapeResource.getBounds().left,- mShapeResource.getBounds().top);
156+
}else {
157+
mShapeResource.draw(canvas);
157158
}
158159
isDrawShapeClear = true;
159160
}
@@ -279,16 +280,16 @@ private void drawShape(Canvas canvas) {
279280
mShapePaint.setXfermode(null);
280281
canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mShapePaint, Canvas.ALL_SAVE_FLAG);
281282
mShapeResource.setBounds(left, top, right, bottom);
282-
float scaleX = 1f;
283-
float scaleY = 1f;
284283
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);
287287
canvas.scale(scaleX,scaleY);
288-
}
289-
mShapeResource.draw(canvas);
290-
if (mShapeResource instanceof PictureDrawable){
288+
canvas.drawPicture(((PictureDrawable) mShapeResource).getPicture());
291289
canvas.scale(1/scaleX,1/scaleY);
290+
canvas.translate(-mShapeResource.getBounds().left,- mShapeResource.getBounds().top);
291+
}else {
292+
mShapeResource.draw(canvas);
292293
}
293294
}
294295
mShapePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

0 commit comments

Comments
 (0)