Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fastdevelop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高超
fastdevelop
Commits
e47c87ae
Commit
e47c87ae
authored
Mar 09, 2020
by
gao.chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加载圆形图片
parent
49394bb6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
19 deletions
+23
-19
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleTransform.java
+23
-19
No files found.
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleTransform.java
View file @
e47c87ae
package
com
.
mayi
.
fastdevelop
.
view
;
package
com
.
mayi
.
fastdevelop
.
view
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapShader
;
import
android.graphics.Canvas
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.graphics.Paint
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuffXfermode
;
import
android.graphics.Rect
;
import
android.graphics.RectF
;
import
com.squareup.picasso.Transformation
;
import
com.squareup.picasso.Transformation
;
...
@@ -14,24 +17,25 @@ public class CircleTransform implements Transformation {
...
@@ -14,24 +17,25 @@ public class CircleTransform implements Transformation {
@Override
@Override
public
Bitmap
transform
(
Bitmap
source
)
{
public
Bitmap
transform
(
Bitmap
source
)
{
int
size
=
Math
.
min
(
source
.
getWidth
(),
source
.
getHeight
());
int
widthLight
=
source
.
getWidth
();
int
x
=
(
source
.
getWidth
()
-
size
)
/
2
;
int
heightLight
=
source
.
getHeight
();
int
y
=
(
source
.
getHeight
()
-
size
)
/
2
;
Bitmap
squaredBitmap
=
Bitmap
.
createBitmap
(
source
,
x
,
y
,
size
,
size
);
Bitmap
output
=
Bitmap
.
createBitmap
(
source
.
getWidth
(),
source
.
getHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
if
(
squaredBitmap
!=
source
)
{
source
.
recycle
();
Canvas
canvas
=
new
Canvas
(
output
);
}
Paint
paintColor
=
new
Paint
();
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
size
,
size
,
source
.
getConfig
());
paintColor
.
setFlags
(
Paint
.
ANTI_ALIAS_FLAG
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
Paint
paint
=
new
Paint
();
RectF
rectF
=
new
RectF
(
new
Rect
(
0
,
0
,
widthLight
,
heightLight
));
BitmapShader
shader
=
new
BitmapShader
(
squaredBitmap
,
BitmapShader
.
TileMode
.
CLAMP
,
BitmapShader
.
TileMode
.
CLAMP
);
canvas
.
drawRoundRect
(
rectF
,
widthLight
/
2
,
heightLight
/
2
,
paintColor
);
paint
.
setShader
(
shader
);
paint
.
setAntiAlias
(
true
);
Paint
paintImage
=
new
Paint
();
float
r
=
size
/
2
f
;
paintImage
.
setXfermode
(
new
PorterDuffXfermode
(
PorterDuff
.
Mode
.
SRC_ATOP
));
canvas
.
drawCircle
(
r
,
r
,
r
,
paint
);
canvas
.
drawBitmap
(
source
,
0
,
0
,
paintImage
);
squaredBitmap
.
recycle
();
source
.
recycle
();
return
bitmap
;
return
output
;
}
}
@Override
@Override
public
String
key
()
{
public
String
key
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment