Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mmm-rain
AndroidUtilCode
提交
28def9b7
A
AndroidUtilCode
项目概览
mmm-rain
/
AndroidUtilCode
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AndroidUtilCode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
28def9b7
编写于
12月 03, 2017
作者:
B
Blankj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
see 12/03 log
上级
f63debd3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
118 addition
and
34 deletion
+118
-34
app/src/main/res/layout/activity_drawer.xml
app/src/main/res/layout/activity_drawer.xml
+1
-1
app/src/main/res/menu/main_drawer.xml
app/src/main/res/menu/main_drawer.xml
+0
-0
utilcode/src/main/java/com/blankj/utilcode/util/ImageUtils.java
...de/src/main/java/com/blankj/utilcode/util/ImageUtils.java
+117
-33
未找到文件。
app/src/main/res/layout/activity_drawer.xml
浏览文件 @
28def9b7
...
...
@@ -24,6 +24,6 @@
android:background=
"@color/white"
android:fitsSystemWindows=
"false"
app:headerLayout=
"@layout/nav_header"
app:menu=
"@menu/
activity_
main_drawer"
/>
app:menu=
"@menu/main_drawer"
/>
</android.support.v4.widget.DrawerLayout>
app/src/main/res/menu/
activity_
main_drawer.xml
→
app/src/main/res/menu/main_drawer.xml
浏览文件 @
28def9b7
文件已移动
utilcode/src/main/java/com/blankj/utilcode/util/ImageUtils.java
浏览文件 @
28def9b7
...
...
@@ -82,7 +82,9 @@ public final class ImageUtils {
* @return bitmap
*/
public
static
Bitmap
bytes2Bitmap
(
final
byte
[]
bytes
)
{
return
(
bytes
==
null
||
bytes
.
length
==
0
)
?
null
:
BitmapFactory
.
decodeByteArray
(
bytes
,
0
,
bytes
.
length
);
return
(
bytes
==
null
||
bytes
.
length
==
0
)
?
null
:
BitmapFactory
.
decodeByteArray
(
bytes
,
0
,
bytes
.
length
);
}
/**
...
...
@@ -101,10 +103,15 @@ public final class ImageUtils {
Bitmap
bitmap
;
if
(
drawable
.
getIntrinsicWidth
()
<=
0
||
drawable
.
getIntrinsicHeight
()
<=
0
)
{
bitmap
=
Bitmap
.
createBitmap
(
1
,
1
,
drawable
.
getOpacity
()
!=
PixelFormat
.
OPAQUE
?
Bitmap
.
Config
.
ARGB_8888
:
Bitmap
.
Config
.
RGB_565
);
drawable
.
getOpacity
()
!=
PixelFormat
.
OPAQUE
?
Bitmap
.
Config
.
ARGB_8888
:
Bitmap
.
Config
.
RGB_565
);
}
else
{
bitmap
=
Bitmap
.
createBitmap
(
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
(),
drawable
.
getOpacity
()
!=
PixelFormat
.
OPAQUE
?
Bitmap
.
Config
.
ARGB_8888
:
Bitmap
.
Config
.
RGB_565
);
bitmap
=
Bitmap
.
createBitmap
(
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
(),
drawable
.
getOpacity
()
!=
PixelFormat
.
OPAQUE
?
Bitmap
.
Config
.
ARGB_8888
:
Bitmap
.
Config
.
RGB_565
);
}
Canvas
canvas
=
new
Canvas
(
bitmap
);
drawable
.
setBounds
(
0
,
0
,
canvas
.
getWidth
(),
canvas
.
getHeight
());
...
...
@@ -151,7 +158,9 @@ public final class ImageUtils {
*/
public
static
Bitmap
view2Bitmap
(
final
View
view
)
{
if
(
view
==
null
)
return
null
;
Bitmap
ret
=
Bitmap
.
createBitmap
(
view
.
getWidth
(),
view
.
getHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
Bitmap
ret
=
Bitmap
.
createBitmap
(
view
.
getWidth
(),
view
.
getHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
ret
);
Drawable
bgDrawable
=
view
.
getBackground
();
if
(
bgDrawable
!=
null
)
{
...
...
@@ -267,7 +276,10 @@ public final class ImageUtils {
* @param maxHeight 最大高度
* @return bitmap
*/
public
static
Bitmap
getBitmap
(
final
byte
[]
data
,
final
int
offset
,
final
int
maxWidth
,
final
int
maxHeight
)
{
public
static
Bitmap
getBitmap
(
final
byte
[]
data
,
final
int
offset
,
final
int
maxWidth
,
final
int
maxHeight
)
{
if
(
data
.
length
==
0
)
return
null
;
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
...
...
@@ -286,7 +298,9 @@ public final class ImageUtils {
public
static
Bitmap
getBitmap
(
@DrawableRes
final
int
resId
)
{
Drawable
drawable
=
ContextCompat
.
getDrawable
(
Utils
.
getApp
(),
resId
);
Canvas
canvas
=
new
Canvas
();
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
(),
Bitmap
.
Config
.
ARGB_8888
);
canvas
.
setBitmap
(
bitmap
);
drawable
.
setBounds
(
0
,
0
,
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
());
drawable
.
draw
(
canvas
);
...
...
@@ -301,7 +315,9 @@ public final class ImageUtils {
* @param maxHeight 最大高度
* @return bitmap
*/
public
static
Bitmap
getBitmap
(
@DrawableRes
final
int
resId
,
final
int
maxWidth
,
final
int
maxHeight
)
{
public
static
Bitmap
getBitmap
(
@DrawableRes
final
int
resId
,
final
int
maxWidth
,
final
int
maxHeight
)
{
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
final
Resources
resources
=
Utils
.
getApp
().
getResources
();
options
.
inJustDecodeBounds
=
true
;
...
...
@@ -330,7 +346,9 @@ public final class ImageUtils {
* @param maxHeight 最大高度
* @return bitmap
*/
public
static
Bitmap
getBitmap
(
final
FileDescriptor
fd
,
final
int
maxWidth
,
final
int
maxHeight
)
{
public
static
Bitmap
getBitmap
(
final
FileDescriptor
fd
,
final
int
maxWidth
,
final
int
maxHeight
)
{
if
(
fd
==
null
)
return
null
;
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
...
...
@@ -361,7 +379,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 缩放后的图片
*/
public
static
Bitmap
scale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
,
final
boolean
recycle
)
{
public
static
Bitmap
scale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
Bitmap
ret
=
Bitmap
.
createScaledBitmap
(
src
,
newWidth
,
newHeight
,
true
);
if
(
recycle
&&
!
src
.
isRecycled
())
src
.
recycle
();
...
...
@@ -389,7 +410,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 缩放后的图片
*/
public
static
Bitmap
scale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
,
final
boolean
recycle
)
{
public
static
Bitmap
scale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
Matrix
matrix
=
new
Matrix
();
matrix
.
setScale
(
scaleWidth
,
scaleHeight
);
...
...
@@ -408,7 +432,11 @@ public final class ImageUtils {
* @param height 裁剪高度
* @return 裁剪后的图片
*/
public
static
Bitmap
clip
(
final
Bitmap
src
,
final
int
x
,
final
int
y
,
final
int
width
,
final
int
height
)
{
public
static
Bitmap
clip
(
final
Bitmap
src
,
final
int
x
,
final
int
y
,
final
int
width
,
final
int
height
)
{
return
clip
(
src
,
x
,
y
,
width
,
height
,
false
);
}
...
...
@@ -423,7 +451,12 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 裁剪后的图片
*/
public
static
Bitmap
clip
(
final
Bitmap
src
,
final
int
x
,
final
int
y
,
final
int
width
,
final
int
height
,
final
boolean
recycle
)
{
public
static
Bitmap
clip
(
final
Bitmap
src
,
final
int
x
,
final
int
y
,
final
int
width
,
final
int
height
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
Bitmap
ret
=
Bitmap
.
createBitmap
(
src
,
x
,
y
,
width
,
height
);
if
(
recycle
&&
!
src
.
isRecycled
())
src
.
recycle
();
...
...
@@ -451,7 +484,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 倾斜后的图片
*/
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
boolean
recycle
)
{
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
boolean
recycle
)
{
return
skew
(
src
,
kx
,
ky
,
0
,
0
,
recycle
);
}
...
...
@@ -465,7 +501,11 @@ public final class ImageUtils {
* @param py 平移因子 y
* @return 倾斜后的图片
*/
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
float
px
,
final
float
py
)
{
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
float
px
,
final
float
py
)
{
return
skew
(
src
,
kx
,
ky
,
px
,
py
,
false
);
}
...
...
@@ -480,7 +520,12 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 倾斜后的图片
*/
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
float
px
,
final
float
py
,
final
boolean
recycle
)
{
public
static
Bitmap
skew
(
final
Bitmap
src
,
final
float
kx
,
final
float
ky
,
final
float
px
,
final
float
py
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
Matrix
matrix
=
new
Matrix
();
matrix
.
setSkew
(
kx
,
ky
,
px
,
py
);
...
...
@@ -498,7 +543,10 @@ public final class ImageUtils {
* @param py 旋转点纵坐标
* @return 旋转后的图片
*/
public
static
Bitmap
rotate
(
final
Bitmap
src
,
final
int
degrees
,
final
float
px
,
final
float
py
)
{
public
static
Bitmap
rotate
(
final
Bitmap
src
,
final
int
degrees
,
final
float
px
,
final
float
py
)
{
return
rotate
(
src
,
degrees
,
px
,
py
,
false
);
}
...
...
@@ -512,7 +560,11 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 旋转后的图片
*/
public
static
Bitmap
rotate
(
final
Bitmap
src
,
final
int
degrees
,
final
float
px
,
final
float
py
,
final
boolean
recycle
)
{
public
static
Bitmap
rotate
(
final
Bitmap
src
,
final
int
degrees
,
final
float
px
,
final
float
py
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
if
(
degrees
==
0
)
return
src
;
Matrix
matrix
=
new
Matrix
();
...
...
@@ -1102,8 +1154,10 @@ public final class ImageUtils {
try
{
rs
=
RenderScript
.
create
(
Utils
.
getApp
());
rs
.
setMessageHandler
(
new
RenderScript
.
RSMessageHandler
());
Allocation
input
=
Allocation
.
createFromBitmap
(
rs
,
ret
,
Allocation
.
MipmapControl
.
MIPMAP_NONE
,
Allocation
.
USAGE_SCRIPT
);
Allocation
input
=
Allocation
.
createFromBitmap
(
rs
,
ret
,
Allocation
.
MipmapControl
.
MIPMAP_NONE
,
Allocation
.
USAGE_SCRIPT
);
Allocation
output
=
Allocation
.
createTyped
(
rs
,
input
.
getType
());
ScriptIntrinsicBlur
blurScript
=
ScriptIntrinsicBlur
.
create
(
rs
,
Element
.
U8_4
(
rs
));
blurScript
.
setInput
(
input
);
...
...
@@ -1343,7 +1397,9 @@ public final class ImageUtils {
* @param format 格式
* @return {@code true}: 成功<br>{@code false}: 失败
*/
public
static
boolean
save
(
final
Bitmap
src
,
final
String
filePath
,
final
CompressFormat
format
)
{
public
static
boolean
save
(
final
Bitmap
src
,
final
String
filePath
,
final
CompressFormat
format
)
{
return
save
(
src
,
getFileByPath
(
filePath
),
format
,
false
);
}
...
...
@@ -1368,7 +1424,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return {@code true}: 成功<br>{@code false}: 失败
*/
public
static
boolean
save
(
final
Bitmap
src
,
final
String
filePath
,
final
CompressFormat
format
,
final
boolean
recycle
)
{
public
static
boolean
save
(
final
Bitmap
src
,
final
String
filePath
,
final
CompressFormat
format
,
final
boolean
recycle
)
{
return
save
(
src
,
getFileByPath
(
filePath
),
format
,
recycle
);
}
...
...
@@ -1381,7 +1440,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return {@code true}: 成功<br>{@code false}: 失败
*/
public
static
boolean
save
(
final
Bitmap
src
,
final
File
file
,
final
CompressFormat
format
,
final
boolean
recycle
)
{
public
static
boolean
save
(
final
Bitmap
src
,
final
File
file
,
final
CompressFormat
format
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
)
||
!
createFileByDeleteOldFile
(
file
))
return
false
;
OutputStream
os
=
null
;
boolean
ret
=
false
;
...
...
@@ -1528,7 +1590,9 @@ public final class ImageUtils {
* @param newHeight 新高度
* @return 缩放压缩后的图片
*/
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
)
{
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
)
{
return
scale
(
src
,
newWidth
,
newHeight
,
false
);
}
...
...
@@ -1541,7 +1605,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 缩放压缩后的图片
*/
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
,
final
boolean
recycle
)
{
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
int
newWidth
,
final
int
newHeight
,
final
boolean
recycle
)
{
return
scale
(
src
,
newWidth
,
newHeight
,
recycle
);
}
...
...
@@ -1553,7 +1620,9 @@ public final class ImageUtils {
* @param scaleHeight 缩放高度倍数
* @return 缩放压缩后的图片
*/
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
)
{
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
)
{
return
scale
(
src
,
scaleWidth
,
scaleHeight
,
false
);
}
...
...
@@ -1566,7 +1635,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 缩放压缩后的图片
*/
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
,
final
boolean
recycle
)
{
public
static
Bitmap
compressByScale
(
final
Bitmap
src
,
final
float
scaleWidth
,
final
float
scaleHeight
,
final
boolean
recycle
)
{
return
scale
(
src
,
scaleWidth
,
scaleHeight
,
recycle
);
}
...
...
@@ -1577,7 +1649,8 @@ public final class ImageUtils {
* @param quality 质量
* @return 质量压缩后的图片
*/
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
@IntRange
(
from
=
0
,
to
=
100
)
final
int
quality
)
{
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
@IntRange
(
from
=
0
,
to
=
100
)
final
int
quality
)
{
return
compressByQuality
(
src
,
quality
,
false
);
}
...
...
@@ -1589,7 +1662,9 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 质量压缩后的图片
*/
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
@IntRange
(
from
=
0
,
to
=
100
)
final
int
quality
,
final
boolean
recycle
)
{
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
@IntRange
(
from
=
0
,
to
=
100
)
final
int
quality
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
src
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
quality
,
baos
);
...
...
@@ -1617,7 +1692,9 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 质量压缩压缩过的图片
*/
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
final
long
maxByteSize
,
final
boolean
recycle
)
{
public
static
Bitmap
compressByQuality
(
final
Bitmap
src
,
final
long
maxByteSize
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
)
||
maxByteSize
<=
0
)
return
null
;
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
src
.
compress
(
CompressFormat
.
JPEG
,
100
,
baos
);
...
...
@@ -1678,7 +1755,9 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 按采样率压缩后的图片
*/
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
sampleSize
,
final
boolean
recycle
)
{
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
sampleSize
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inSampleSize
=
sampleSize
;
...
...
@@ -1697,7 +1776,9 @@ public final class ImageUtils {
* @param maxHeight 最大高度
* @return 按采样率压缩后的图片
*/
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
maxWidth
,
final
int
maxHeight
)
{
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
maxWidth
,
final
int
maxHeight
)
{
return
compressBySampleSize
(
src
,
maxWidth
,
maxHeight
,
false
);
}
...
...
@@ -1710,7 +1791,10 @@ public final class ImageUtils {
* @param recycle 是否回收
* @return 按采样率压缩后的图片
*/
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
maxWidth
,
final
int
maxHeight
,
final
boolean
recycle
)
{
public
static
Bitmap
compressBySampleSize
(
final
Bitmap
src
,
final
int
maxWidth
,
final
int
maxHeight
,
final
boolean
recycle
)
{
if
(
isEmptyBitmap
(
src
))
return
null
;
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录