public class ImageUtils
extends java.lang.Object
author: Blankj blog : http://blankj.com time : 2016/8/12 desc : 图片相关工具类
Modifier and Type | Method and Description |
---|---|
static Bitmap |
addFrame(Bitmap src,
int borderWidth,
int color)
添加颜色边框
|
static Bitmap |
addFrame(Bitmap src,
int borderWidth,
int color,
boolean recycle)
添加颜色边框
|
static Bitmap |
addImageWatermark(Bitmap src,
Bitmap watermark,
int x,
int y,
int alpha)
添加图片水印
|
static Bitmap |
addImageWatermark(Bitmap src,
Bitmap watermark,
int x,
int y,
int alpha,
boolean recycle)
添加图片水印
|
static Bitmap |
addReflection(Bitmap src,
int reflectionHeight)
添加倒影
|
static Bitmap |
addReflection(Bitmap src,
int reflectionHeight,
boolean recycle)
添加倒影
|
static Bitmap |
addTextWatermark(Bitmap src,
java.lang.String content,
float textSize,
int color,
float x,
float y,
boolean recycle)
添加文字水印
|
static Bitmap |
addTextWatermark(Bitmap src,
java.lang.String content,
int textSize,
int color,
float x,
float y)
添加文字水印
|
static byte[] |
bitmap2Bytes(Bitmap bitmap,
CompressFormat format)
bitmap转byteArr
|
static Drawable |
bitmap2Drawable(Resources res,
Bitmap bitmap)
bitmap转drawable
|
static Bitmap |
bytes2Bitmap(byte[] bytes)
byteArr转bitmap
|
static Drawable |
bytes2Drawable(Resources res,
byte[] bytes)
byteArr转drawable
|
static Bitmap |
clip(Bitmap src,
int x,
int y,
int width,
int height)
裁剪图片
|
static Bitmap |
clip(Bitmap src,
int x,
int y,
int width,
int height,
boolean recycle)
裁剪图片
|
static Bitmap |
compressByQuality(Bitmap src,
int quality)
按质量压缩
|
static Bitmap |
compressByQuality(Bitmap src,
int quality,
boolean recycle)
按质量压缩
|
static Bitmap |
compressByQuality(Bitmap src,
long maxByteSize)
按质量压缩
|
static Bitmap |
compressByQuality(Bitmap src,
long maxByteSize,
boolean recycle)
按质量压缩
|
static Bitmap |
compressBySampleSize(Bitmap src,
int sampleSize)
按采样大小压缩
|
static Bitmap |
compressBySampleSize(Bitmap src,
int sampleSize,
boolean recycle)
按采样大小压缩
|
static Bitmap |
compressByScale(Bitmap src,
float scaleWidth,
float scaleHeight)
按缩放压缩
|
static Bitmap |
compressByScale(Bitmap src,
float scaleWidth,
float scaleHeight,
boolean recycle)
按缩放压缩
|
static Bitmap |
compressByScale(Bitmap src,
int newWidth,
int newHeight)
按缩放压缩
|
static Bitmap |
compressByScale(Bitmap src,
int newWidth,
int newHeight,
boolean recycle)
按缩放压缩
|
static Bitmap |
drawable2Bitmap(Drawable drawable)
drawable转bitmap
|
static byte[] |
drawable2Bytes(Drawable drawable,
CompressFormat format)
drawable转byteArr
|
static Bitmap |
fastBlur(Bitmap src,
float scale,
float radius)
快速模糊
|
static Bitmap |
fastBlur(Bitmap src,
float scale,
float radius,
boolean recycle)
快速模糊图片
|
static Bitmap |
getBitmap(byte[] data,
int offset)
获取bitmap
|
static Bitmap |
getBitmap(byte[] data,
int offset,
int maxWidth,
int maxHeight)
获取bitmap
|
static Bitmap |
getBitmap(java.io.File file)
获取bitmap
|
static Bitmap |
getBitmap(java.io.FileDescriptor fd)
获取bitmap
|
static Bitmap |
getBitmap(java.io.FileDescriptor fd,
int maxWidth,
int maxHeight)
获取bitmap
|
static Bitmap |
getBitmap(java.io.File file,
int maxWidth,
int maxHeight)
获取bitmap
|
static Bitmap |
getBitmap(java.io.InputStream is)
获取bitmap
|
static Bitmap |
getBitmap(java.io.InputStream is,
int maxWidth,
int maxHeight)
获取bitmap
|
static Bitmap |
getBitmap(Resources res,
int id)
获取bitmap
|
static Bitmap |
getBitmap(Resources res,
int id,
int maxWidth,
int maxHeight)
获取bitmap
|
static Bitmap |
getBitmap(java.lang.String filePath)
获取bitmap
|
static Bitmap |
getBitmap(java.lang.String filePath,
int maxWidth,
int maxHeight)
获取bitmap
|
static java.lang.String |
getImageType(byte[] bytes)
获取图片类型
|
static java.lang.String |
getImageType(java.io.File file)
获取图片类型
|
static java.lang.String |
getImageType(java.io.InputStream is)
流获取图片类型
|
static java.lang.String |
getImageType(java.lang.String filePath)
获取图片类型
|
static int |
getRotateDegree(java.lang.String filePath)
获取图片旋转角度
|
static boolean |
isImage(java.io.File file)
根据文件名判断文件是否为图片
|
static boolean |
isImage(java.lang.String filePath)
根据文件名判断文件是否为图片
|
static Bitmap |
renderScriptBlur(Context context,
Bitmap src,
float radius)
renderScript模糊图片
|
static Bitmap |
rotate(Bitmap src,
int degrees,
float px,
float py)
旋转图片
|
static Bitmap |
rotate(Bitmap src,
int degrees,
float px,
float py,
boolean recycle)
旋转图片
|
static boolean |
save(Bitmap src,
java.io.File file,
CompressFormat format)
保存图片
|
static boolean |
save(Bitmap src,
java.io.File file,
CompressFormat format,
boolean recycle)
保存图片
|
static boolean |
save(Bitmap src,
java.lang.String filePath,
CompressFormat format)
保存图片
|
static boolean |
save(Bitmap src,
java.lang.String filePath,
CompressFormat format,
boolean recycle)
保存图片
|
static Bitmap |
scale(Bitmap src,
float scaleWidth,
float scaleHeight)
缩放图片
|
static Bitmap |
scale(Bitmap src,
float scaleWidth,
float scaleHeight,
boolean recycle)
缩放图片
|
static Bitmap |
scale(Bitmap src,
int newWidth,
int newHeight)
缩放图片
|
static Bitmap |
scale(Bitmap src,
int newWidth,
int newHeight,
boolean recycle)
缩放图片
|
static Bitmap |
skew(Bitmap src,
float kx,
float ky)
倾斜图片
|
static Bitmap |
skew(Bitmap src,
float kx,
float ky,
boolean recycle)
倾斜图片
|
static Bitmap |
skew(Bitmap src,
float kx,
float ky,
float px,
float py)
倾斜图片
|
static Bitmap |
skew(Bitmap src,
float kx,
float ky,
float px,
float py,
boolean recycle)
倾斜图片
|
static Bitmap |
stackBlur(Bitmap src,
int radius,
boolean recycle)
stack模糊图片
|
static Bitmap |
toAlpha(Bitmap src)
转为alpha位图
|
static Bitmap |
toAlpha(Bitmap src,
java.lang.Boolean recycle)
转为alpha位图
|
static Bitmap |
toGray(Bitmap src)
转为灰度图片
|
static Bitmap |
toGray(Bitmap src,
boolean recycle)
转为灰度图片
|
static Bitmap |
toRound(Bitmap src)
转为圆形图片
|
static Bitmap |
toRound(Bitmap src,
boolean recycle)
转为圆形图片
|
static Bitmap |
toRoundCorner(Bitmap src,
float radius)
转为圆角图片
|
static Bitmap |
toRoundCorner(Bitmap src,
float radius,
boolean recycle)
转为圆角图片
|
static Bitmap |
view2Bitmap(View view)
view转Bitmap
|
public static byte[] bitmap2Bytes(Bitmap bitmap, CompressFormat format)
bitmap
- bitmap对象format
- 格式public static Bitmap bytes2Bitmap(byte[] bytes)
bytes
- 字节数组public static Bitmap drawable2Bitmap(Drawable drawable)
drawable
- drawable对象public static Drawable bitmap2Drawable(Resources res, Bitmap bitmap)
res
- resources对象bitmap
- bitmap对象public static byte[] drawable2Bytes(Drawable drawable, CompressFormat format)
drawable
- drawable对象format
- 格式public static Drawable bytes2Drawable(Resources res, byte[] bytes)
res
- resources对象bytes
- 字节数组public static Bitmap view2Bitmap(View view)
view
- 视图public static Bitmap getBitmap(java.io.File file)
file
- 文件public static Bitmap getBitmap(java.io.File file, int maxWidth, int maxHeight)
file
- 文件maxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap getBitmap(java.lang.String filePath)
filePath
- 文件路径public static Bitmap getBitmap(java.lang.String filePath, int maxWidth, int maxHeight)
filePath
- 文件路径maxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap getBitmap(java.io.InputStream is)
is
- 输入流public static Bitmap getBitmap(java.io.InputStream is, int maxWidth, int maxHeight)
is
- 输入流maxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap getBitmap(byte[] data, int offset)
data
- 数据offset
- 偏移量public static Bitmap getBitmap(byte[] data, int offset, int maxWidth, int maxHeight)
data
- 数据offset
- 偏移量maxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap getBitmap(Resources res, int id)
res
- 资源对象id
- 资源idpublic static Bitmap getBitmap(Resources res, int id, int maxWidth, int maxHeight)
res
- 资源对象id
- 资源idmaxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap getBitmap(java.io.FileDescriptor fd)
fd
- 文件描述public static Bitmap getBitmap(java.io.FileDescriptor fd, int maxWidth, int maxHeight)
fd
- 文件描述maxWidth
- 最大宽度maxHeight
- 最大高度public static Bitmap scale(Bitmap src, int newWidth, int newHeight)
src
- 源图片newWidth
- 新宽度newHeight
- 新高度public static Bitmap scale(Bitmap src, int newWidth, int newHeight, boolean recycle)
src
- 源图片newWidth
- 新宽度newHeight
- 新高度recycle
- 是否回收public static Bitmap scale(Bitmap src, float scaleWidth, float scaleHeight)
src
- 源图片scaleWidth
- 缩放宽度倍数scaleHeight
- 缩放高度倍数public static Bitmap scale(Bitmap src, float scaleWidth, float scaleHeight, boolean recycle)
src
- 源图片scaleWidth
- 缩放宽度倍数scaleHeight
- 缩放高度倍数recycle
- 是否回收public static Bitmap clip(Bitmap src, int x, int y, int width, int height)
src
- 源图片x
- 开始坐标xy
- 开始坐标ywidth
- 裁剪宽度height
- 裁剪高度public static Bitmap clip(Bitmap src, int x, int y, int width, int height, boolean recycle)
src
- 源图片x
- 开始坐标xy
- 开始坐标ywidth
- 裁剪宽度height
- 裁剪高度recycle
- 是否回收public static Bitmap skew(Bitmap src, float kx, float ky)
src
- 源图片kx
- 倾斜因子xky
- 倾斜因子ypublic static Bitmap skew(Bitmap src, float kx, float ky, boolean recycle)
src
- 源图片kx
- 倾斜因子xky
- 倾斜因子yrecycle
- 是否回收public static Bitmap skew(Bitmap src, float kx, float ky, float px, float py)
src
- 源图片kx
- 倾斜因子xky
- 倾斜因子ypx
- 平移因子xpy
- 平移因子ypublic static Bitmap skew(Bitmap src, float kx, float ky, float px, float py, boolean recycle)
src
- 源图片kx
- 倾斜因子xky
- 倾斜因子ypx
- 平移因子xpy
- 平移因子yrecycle
- 是否回收public static Bitmap rotate(Bitmap src, int degrees, float px, float py)
src
- 源图片degrees
- 旋转角度px
- 旋转点横坐标py
- 旋转点纵坐标public static Bitmap rotate(Bitmap src, int degrees, float px, float py, boolean recycle)
src
- 源图片degrees
- 旋转角度px
- 旋转点横坐标py
- 旋转点纵坐标recycle
- 是否回收public static int getRotateDegree(java.lang.String filePath)
filePath
- 文件路径public static Bitmap toRound(Bitmap src)
src
- 源图片public static Bitmap toRound(Bitmap src, boolean recycle)
src
- 源图片recycle
- 是否回收public static Bitmap toRoundCorner(Bitmap src, float radius)
src
- 源图片radius
- 圆角的度数public static Bitmap toRoundCorner(Bitmap src, float radius, boolean recycle)
src
- 源图片radius
- 圆角的度数recycle
- 是否回收public static Bitmap fastBlur(Bitmap src, float scale, float radius)
先缩小原图,对小图进行模糊,再放大回原先尺寸
src
- 源图片scale
- 缩放比例(0...1)radius
- 模糊半径public static Bitmap fastBlur(Bitmap src, float scale, float radius, boolean recycle)
先缩小原图,对小图进行模糊,再放大回原先尺寸
src
- 源图片scale
- 缩放比例(0...1)radius
- 模糊半径(0...25)recycle
- 是否回收public static Bitmap renderScriptBlur(Context context, Bitmap src, float radius)
API大于17
context
- 上下文src
- 源图片radius
- 模糊半径(0...25)public static Bitmap stackBlur(Bitmap src, int radius, boolean recycle)
src
- 源图片radius
- 模糊半径recycle
- 是否回收public static Bitmap addFrame(Bitmap src, int borderWidth, int color)
src
- 源图片borderWidth
- 边框宽度color
- 边框的颜色值public static Bitmap addFrame(Bitmap src, int borderWidth, int color, boolean recycle)
src
- 源图片borderWidth
- 边框宽度color
- 边框的颜色值recycle
- 是否回收public static Bitmap addReflection(Bitmap src, int reflectionHeight)
src
- 源图片的reflectionHeight
- 倒影高度public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle)
src
- 源图片的reflectionHeight
- 倒影高度recycle
- 是否回收public static Bitmap addTextWatermark(Bitmap src, java.lang.String content, int textSize, int color, float x, float y)
src
- 源图片content
- 水印文本textSize
- 水印字体大小color
- 水印字体颜色x
- 起始坐标xy
- 起始坐标ypublic static Bitmap addTextWatermark(Bitmap src, java.lang.String content, float textSize, int color, float x, float y, boolean recycle)
src
- 源图片content
- 水印文本textSize
- 水印字体大小color
- 水印字体颜色x
- 起始坐标xy
- 起始坐标yrecycle
- 是否回收public static Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha)
src
- 源图片watermark
- 图片水印x
- 起始坐标xy
- 起始坐标yalpha
- 透明度public static Bitmap addImageWatermark(Bitmap src, Bitmap watermark, int x, int y, int alpha, boolean recycle)
src
- 源图片watermark
- 图片水印x
- 起始坐标xy
- 起始坐标yalpha
- 透明度recycle
- 是否回收public static Bitmap toAlpha(Bitmap src)
src
- 源图片public static Bitmap toAlpha(Bitmap src, java.lang.Boolean recycle)
src
- 源图片recycle
- 是否回收public static Bitmap toGray(Bitmap src)
src
- 源图片public static Bitmap toGray(Bitmap src, boolean recycle)
src
- 源图片recycle
- 是否回收public static boolean save(Bitmap src, java.lang.String filePath, CompressFormat format)
src
- 源图片filePath
- 要保存到的文件路径format
- 格式true
: 成功false
: 失败public static boolean save(Bitmap src, java.io.File file, CompressFormat format)
src
- 源图片file
- 要保存到的文件format
- 格式true
: 成功false
: 失败public static boolean save(Bitmap src, java.lang.String filePath, CompressFormat format, boolean recycle)
src
- 源图片filePath
- 要保存到的文件路径format
- 格式recycle
- 是否回收true
: 成功false
: 失败public static boolean save(Bitmap src, java.io.File file, CompressFormat format, boolean recycle)
src
- 源图片file
- 要保存到的文件format
- 格式recycle
- 是否回收true
: 成功false
: 失败public static boolean isImage(java.io.File file)
file
- 文件true
: 是false
: 否public static boolean isImage(java.lang.String filePath)
filePath
- 文件路径true
: 是false
: 否public static java.lang.String getImageType(java.lang.String filePath)
filePath
- 文件路径public static java.lang.String getImageType(java.io.File file)
file
- 文件public static java.lang.String getImageType(java.io.InputStream is)
is
- 图片输入流public static java.lang.String getImageType(byte[] bytes)
bytes
- bitmap的前8字节public static Bitmap compressByScale(Bitmap src, int newWidth, int newHeight)
src
- 源图片newWidth
- 新宽度newHeight
- 新高度public static Bitmap compressByScale(Bitmap src, int newWidth, int newHeight, boolean recycle)
src
- 源图片newWidth
- 新宽度newHeight
- 新高度recycle
- 是否回收public static Bitmap compressByScale(Bitmap src, float scaleWidth, float scaleHeight)
src
- 源图片scaleWidth
- 缩放宽度倍数scaleHeight
- 缩放高度倍数public static Bitmap compressByScale(Bitmap src, float scaleWidth, float scaleHeight, boolean recycle)
src
- 源图片scaleWidth
- 缩放宽度倍数scaleHeight
- 缩放高度倍数recycle
- 是否回收public static Bitmap compressByQuality(Bitmap src, int quality)
src
- 源图片quality
- 质量public static Bitmap compressByQuality(Bitmap src, int quality, boolean recycle)
src
- 源图片quality
- 质量recycle
- 是否回收public static Bitmap compressByQuality(Bitmap src, long maxByteSize)
src
- 源图片maxByteSize
- 允许最大值字节数public static Bitmap compressByQuality(Bitmap src, long maxByteSize, boolean recycle)
src
- 源图片maxByteSize
- 允许最大值字节数recycle
- 是否回收public static Bitmap compressBySampleSize(Bitmap src, int sampleSize)
src
- 源图片sampleSize
- 采样率大小public static Bitmap compressBySampleSize(Bitmap src, int sampleSize, boolean recycle)
src
- 源图片sampleSize
- 采样率大小recycle
- 是否回收