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
b32c1faf
Commit
b32c1faf
authored
Dec 19, 2019
by
gao.chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善加载图片
parent
54d20ace
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
1 deletions
+130
-1
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleCornerForm.java
+45
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleTransform.java
+40
-0
fastDevelop/src/main/java/com/mayi/fastdevelop/view/LoadingPictures.java
+45
-1
No files found.
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleCornerForm.java
0 → 100644
View file @
b32c1faf
package
com
.
mayi
.
fastdevelop
.
view
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
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
;
/**
* 圆角切片
*/
public
class
CircleCornerForm
implements
Transformation
{
@Override
public
Bitmap
transform
(
Bitmap
source
)
{
int
widthLight
=
source
.
getWidth
();
int
heightLight
=
source
.
getHeight
();
Bitmap
output
=
Bitmap
.
createBitmap
(
source
.
getWidth
(),
source
.
getHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
output
);
Paint
paintColor
=
new
Paint
();
paintColor
.
setFlags
(
Paint
.
ANTI_ALIAS_FLAG
);
RectF
rectF
=
new
RectF
(
new
Rect
(
0
,
0
,
widthLight
,
heightLight
));
canvas
.
drawRoundRect
(
rectF
,
widthLight
/
5
,
heightLight
/
5
,
paintColor
);
Paint
paintImage
=
new
Paint
();
paintImage
.
setXfermode
(
new
PorterDuffXfermode
(
PorterDuff
.
Mode
.
SRC_ATOP
));
canvas
.
drawBitmap
(
source
,
0
,
0
,
paintImage
);
source
.
recycle
();
return
output
;
}
@Override
public
String
key
()
{
return
"roundcorner"
;
}
}
fastDevelop/src/main/java/com/mayi/fastdevelop/view/CircleTransform.java
0 → 100644
View file @
b32c1faf
package
com
.
mayi
.
fastdevelop
.
view
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapShader
;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
com.squareup.picasso.Transformation
;
/**
* 圆形图片
*/
public
class
CircleTransform
implements
Transformation
{
@Override
public
Bitmap
transform
(
Bitmap
source
)
{
int
size
=
Math
.
min
(
source
.
getWidth
(),
source
.
getHeight
());
int
x
=
(
source
.
getWidth
()
-
size
)
/
2
;
int
y
=
(
source
.
getHeight
()
-
size
)
/
2
;
Bitmap
squaredBitmap
=
Bitmap
.
createBitmap
(
source
,
x
,
y
,
size
,
size
);
if
(
squaredBitmap
!=
source
)
{
source
.
recycle
();
}
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
size
,
size
,
source
.
getConfig
());
Canvas
canvas
=
new
Canvas
(
bitmap
);
Paint
paint
=
new
Paint
();
BitmapShader
shader
=
new
BitmapShader
(
squaredBitmap
,
BitmapShader
.
TileMode
.
CLAMP
,
BitmapShader
.
TileMode
.
CLAMP
);
paint
.
setShader
(
shader
);
paint
.
setAntiAlias
(
true
);
float
r
=
size
/
2
f
;
canvas
.
drawCircle
(
r
,
r
,
r
,
paint
);
squaredBitmap
.
recycle
();
return
bitmap
;
}
@Override
public
String
key
()
{
return
"circle"
;
}
}
fastDevelop/src/main/java/com/mayi/fastdevelop/view/LoadingPictures.java
View file @
b32c1faf
package
com
.
mayi
.
fastdevelop
.
view
;
import
android.text.TextUtils
;
import
android.widget.ImageView
;
import
com.mayi.fastdevelop.R
;
...
...
@@ -14,7 +15,43 @@ public class LoadingPictures {
public
static
int
error
=
R
.
mipmap
.
loading_pictures_error_icon
;
public
static
int
placeholder
=
R
.
mipmap
.
loading_pictures_placeholder_icon
;
//加载圆角图片
public
static
void
loadUriCircleCornerForm
(
String
url
,
ImageView
img
)
{
if
(
TextUtils
.
isEmpty
(
url
))
{
Picasso
.
with
(
img
.
getContext
()).
load
(
error
).
transform
(
new
CircleCornerForm
()).
into
(
img
);
}
else
{
Picasso
.
with
(
img
.
getContext
())
.
load
(
url
)
.
resize
(
2000
,
2000
)
.
onlyScaleDown
()
// 如果图片规格大于2000*2000,将只会被resize
.
transform
(
new
CircleCornerForm
())
.
placeholder
(
placeholder
)
.
error
(
error
)
.
into
(
img
);
}
}
//加载圆形图片
public
static
void
loadUriCircleTransform
(
String
url
,
ImageView
img
)
{
if
(
TextUtils
.
isEmpty
(
url
))
{
Picasso
.
with
(
img
.
getContext
()).
load
(
error
).
transform
(
new
CircleTransform
()).
into
(
img
);
}
else
{
Picasso
.
with
(
img
.
getContext
())
.
load
(
url
)
.
resize
(
2000
,
2000
)
.
onlyScaleDown
()
// 如果图片规格大于2000*2000,将只会被resize
.
transform
(
new
CircleTransform
())
.
placeholder
(
placeholder
)
.
error
(
error
)
.
into
(
img
);
}
}
//加载网络图片
public
static
void
loadUri
(
String
url
,
ImageView
img
)
{
if
(
TextUtils
.
isEmpty
(
url
))
{
Picasso
.
with
(
img
.
getContext
()).
load
(
error
).
into
(
img
);
}
else
{
Picasso
.
with
(
img
.
getContext
())
.
load
(
url
)
.
resize
(
2000
,
2000
)
...
...
@@ -23,8 +60,13 @@ public class LoadingPictures {
.
error
(
error
)
.
into
(
img
);
}
}
//加载文件图片
public
static
void
loadFile
(
File
file
,
ImageView
img
)
{
if
(
file
==
null
)
{
Picasso
.
with
(
img
.
getContext
()).
load
(
error
).
into
(
img
);
}
else
{
Picasso
.
with
(
img
.
getContext
())
.
load
(
file
)
.
resize
(
2000
,
2000
)
...
...
@@ -32,9 +74,11 @@ public class LoadingPictures {
.
error
(
error
)
.
into
(
img
);
}
}
//加载文件图片
public
static
void
loadFile
(
String
pathname
,
ImageView
img
)
{
loadFile
(
new
File
(
pathname
),
img
);
loadFile
(
new
File
(
pathname
),
img
);
}
}
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