Skip to content

Commit c02857f

Browse files
committed
圆角绘制优化
1 parent eaf236b commit c02857f

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

lib/src/main/java/org/evilbinary/tv/widget/RoundImpl.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class RoundImpl {
3333
private RoundedView mView;
3434

3535

36-
public RoundImpl(RoundedView view,Context context, AttributeSet attrs, int defStyle) {
37-
init(context,attrs,defStyle);
38-
mView=view;
36+
public RoundImpl(RoundedView view, Context context, AttributeSet attrs, int defStyle) {
37+
init(context, attrs, defStyle);
38+
mView = view;
3939
}
4040

4141

@@ -70,12 +70,17 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
7070
a.recycle();
7171

7272
}
73+
7374
public interface RoundedView {
7475

7576
public void drawSuper(Canvas canvas);
77+
7678
public Context getContext();
79+
7780
public RoundImpl getRoundImpl();
81+
7882
public int getWidth();
83+
7984
public int getHeight();
8085
}
8186

@@ -91,25 +96,16 @@ public void draw(Canvas canvas) {
9196
int height = mView.getHeight();
9297

9398
int count = canvas.save();
94-
95-
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
96-
Canvas canvas2 = new Canvas(bitmap);
97-
int count2 = canvas2.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG);
99+
int count2 = canvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG);
98100

99101
addRoundPath(width, height);
100-
101-
102-
mView.drawSuper(canvas2);
103-
104-
105-
canvas2.drawPath(mPath, mPaint);
106-
107-
canvas2.restoreToCount(count2);
108-
canvas.drawBitmap(bitmap, 0, 0, null);
109-
bitmap.recycle();
102+
mView.drawSuper(canvas);
103+
canvas.drawPath(mPath, mPaint);
104+
canvas.restoreToCount(count2);
110105
//drawBorder(canvas);
111106
canvas.restoreToCount(count);
112107

108+
113109
}
114110

115111
private void addRoundPath(int width, int height) {
@@ -189,5 +185,4 @@ public static Bitmap getRoundBitmap(Bitmap bitmap, int roundWidth, int roundHeig
189185
}
190186

191187

192-
193188
}

0 commit comments

Comments
 (0)