public final class BitmapUtil
extends java.lang.Object
| 构造器和说明 |
|---|
BitmapUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
计算当前图片压缩到制定大小需要的压缩比率
计算压缩比例值
|
static android.graphics.Bitmap |
compressBitmap(android.graphics.Bitmap image,
int max)
质量压缩
|
static boolean |
compressLocalBitmap(java.lang.String path,
java.lang.String savePath,
int size,
int quality)
该方法有个缺陷 图片大小超过1M就会内存溢出!!!
|
static android.graphics.drawable.Drawable |
convertBitmapToDrawable(android.content.Context context,
android.graphics.Bitmap bitmap)
将bitmap对象转换为drawable对象
|
static android.graphics.Bitmap |
convertDrawableToBitmap(android.graphics.drawable.Drawable drawable)
将Drawable转换为bitmap对象
|
static android.graphics.Bitmap |
createCircleImage(android.graphics.Bitmap source,
int min)
根据原图和变长绘制圆形图片
|
static android.graphics.Bitmap |
createCircleImage(android.content.Context context,
android.graphics.Bitmap bitmap)
转换图片成圆形
|
static android.graphics.Bitmap |
decodeSampledBitmapFromBitmap(android.graphics.Bitmap bitmap,
int reqWidth,
int reqHeight)
将bitmap对象压缩到指定大小
|
static android.graphics.Bitmap |
decodeSampledBitmapFromFile(java.lang.String filepath,
int reqWidth,
int reqHeight)
根据文件路径得到bitmap对象 AppSuggestActivity
|
static android.graphics.Bitmap |
decodeSampledBitmapFromResource(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight)
得到drawable中指定图片的bitmap对象
|
static android.graphics.Bitmap |
enlargeOrZoomBitmap(android.graphics.Bitmap source,
int requireWidth,
int requireHeight)
放大或缩小指定的bitmap
|
static java.lang.String |
getBase64StringByPath(java.lang.String picPath)
将指定路径的图片转换为Base64字符串
|
static java.lang.String |
getBase64StringByPath(java.lang.String picPath,
int qualityValue)
将指定路径的照片转换为Base64编码的字符串
|
static android.graphics.Bitmap |
getBitmapByPath(java.lang.String strImgPath)
获得指定图片路径的Bitmap对象
|
static android.graphics.Bitmap |
getBitmapByPath(java.lang.String path,
int screenWidth,
int screenHeight)
通过指定图片路径获得Bitmap对象
|
static android.graphics.Bitmap |
getBitmapFromByte(byte[] b)
将byte数组转换为bitmap
|
static byte[] |
getByte(android.graphics.Bitmap bitmap,
int quality)
将bitmap转换为byte[]
|
static android.graphics.BitmapFactory.Options |
getOptions(java.lang.String path)
获得图像的Options
|
static int |
getPicAngle(java.lang.String path)
获得指定路径图片旋转的角度 若没有旋转则返回0
|
static void |
getPicFromBase64String(java.lang.String picString,
java.lang.String picPath)
将Base64字符串转换为图片存储到指定路径
|
static android.graphics.Bitmap |
rotateBitmap(android.content.Context context,
int imgId,
int angle)
旋转图像(drawable中的图片)
|
static android.graphics.Bitmap |
rotateBitmap(int angle,
android.graphics.Bitmap bitmap)
旋转图片(Bitmap对象)
|
static java.lang.Boolean |
saveBitmapInLocal(android.content.Context c,
android.graphics.Bitmap b,
java.lang.String folderName,
java.lang.String fileType,
android.graphics.Bitmap.CompressFormat f,
int q)
将bitmap保存在本地
|
static java.lang.Boolean |
saveBitmapInLocal2(android.graphics.Bitmap b,
java.lang.String p,
android.graphics.Bitmap.CompressFormat f,
int q)
将bitmap保存在本地
|
static java.lang.Boolean |
saveBitmapInLocal3(android.graphics.Bitmap b,
java.lang.String folderPath,
java.lang.String fileName,
android.graphics.Bitmap.CompressFormat f,
int q)
将bitmap保存在本地
|
static android.graphics.Bitmap |
tailorBitmap(android.graphics.Bitmap bitmap,
android.graphics.Rect oldRect,
android.graphics.Rect newRect)
裁剪图像 这其实不是严格意义上的裁剪 只是将原图像的部分显示在界面上
|
static android.graphics.Bitmap |
zoomBitmap(android.graphics.Bitmap bitmap,
int width,
int height)
缩放图像(Bitamp对象)到指定大小
|
public static android.graphics.BitmapFactory.Options getOptions(java.lang.String path)
path - pathpublic static android.graphics.Bitmap getBitmapByPath(java.lang.String strImgPath)
strImgPath - pathpublic static android.graphics.Bitmap getBitmapByPath(java.lang.String path,
int screenWidth,
int screenHeight)
throws java.io.FileNotFoundException
path - pathscreenWidth - widthscreenHeight - heightjava.io.FileNotFoundException - not found filepublic static android.graphics.Bitmap getBitmapFromByte(byte[] b)
b - bytepublic static java.lang.String getBase64StringByPath(java.lang.String picPath)
picPath - picPathpublic static java.lang.String getBase64StringByPath(java.lang.String picPath,
int qualityValue)
picPath - 照片路径qualityValue - qualityValuepublic static byte[] getByte(android.graphics.Bitmap bitmap,
int quality)
bitmap - bitmapquality - qualitypublic static void getPicFromBase64String(java.lang.String picString,
java.lang.String picPath)
picString - picStringpicPath - picPathpublic static int getPicAngle(java.lang.String path)
path - 指定的图片路径public static android.graphics.Bitmap rotateBitmap(int angle,
android.graphics.Bitmap bitmap)
angle - 旋转的角度bitmap - 需要旋转的bitmap对象public static android.graphics.Bitmap rotateBitmap(android.content.Context context,
int imgId,
int angle)
context - contextimgId - imgIdangle - anglepublic static android.graphics.Bitmap zoomBitmap(android.graphics.Bitmap bitmap,
int width,
int height)
bitmap - bitmapwidth - widthheight - heightpublic static android.graphics.Bitmap tailorBitmap(android.graphics.Bitmap bitmap,
android.graphics.Rect oldRect,
android.graphics.Rect newRect)
bitmap - bitmapoldRect - Rect 对象表示一个矩形区域,从 (0,0) 到 (200,200) 之间的矩形区域newRect - 将 mBitmap 的 (100,100) 到 (300,300) 区域拿出来,自动缩放并画到屏幕的 (100,100) 到 (200,200) 区域。public static android.graphics.Bitmap convertDrawableToBitmap(android.graphics.drawable.Drawable drawable)
drawable - drawablepublic static android.graphics.drawable.Drawable convertBitmapToDrawable(android.content.Context context,
android.graphics.Bitmap bitmap)
context - Contextbitmap - 需要转换的bitmap对象public static java.lang.Boolean saveBitmapInLocal(android.content.Context c,
android.graphics.Bitmap b,
java.lang.String folderName,
java.lang.String fileType,
android.graphics.Bitmap.CompressFormat f,
int q)
c - Contextb - 被保存的bitmap对象folderName - 要创建的文件夹名称fileType - 要创建的文件类型 png jpgf - bitmap输出到本地的图像格式q - bitmap输出的图像质量public static java.lang.Boolean saveBitmapInLocal2(android.graphics.Bitmap b,
java.lang.String p,
android.graphics.Bitmap.CompressFormat f,
int q)
b - 被保存的bitmap对象f - 输出的图像格式 JPG PNG等q - 输出的图像质量 0-100p - 保存的全路径 文件夹路径+文件名public static java.lang.Boolean saveBitmapInLocal3(android.graphics.Bitmap b,
java.lang.String folderPath,
java.lang.String fileName,
android.graphics.Bitmap.CompressFormat f,
int q)
b - 被存储的bitmap对象folderPath - 存储的文件夹路径fileName - 存储的文件名f - 输出的图像格式 JPG PNG等q - 输出的质量 0-100public static boolean compressLocalBitmap(java.lang.String path,
java.lang.String savePath,
int size,
int quality)
path - //图片真实路径savePath - //图片将要被存储到的路径size - //压缩比率 建议为1-2中间quality - //压缩的质量public static android.graphics.Bitmap decodeSampledBitmapFromFile(java.lang.String filepath,
int reqWidth,
int reqHeight)
filepath - filepathreqWidth - 所需图片压缩尺寸最小宽度reqHeight - 所需图片压缩尺寸最小高度public static android.graphics.Bitmap decodeSampledBitmapFromResource(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight)
res - Context.getResource()resId - 被转换的图片的idreqWidth - 所需图片压缩尺寸最小宽度reqHeight - 所需图片压缩尺寸最小高度public static android.graphics.Bitmap decodeSampledBitmapFromBitmap(android.graphics.Bitmap bitmap,
int reqWidth,
int reqHeight)
bitmap - 被压缩的bitmap对象reqWidth - 需要的宽度reqHeight - 需要的高度public static int calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
options - 解析图片的配置信息reqWidth - 所需图片压缩尺寸最小宽度reqHeight - 所需图片压缩尺寸最小高度public static android.graphics.Bitmap compressBitmap(android.graphics.Bitmap image,
int max)
image - 被压缩的bitmap对象max - 被压缩后的最大大小 (KB)public static android.graphics.Bitmap enlargeOrZoomBitmap(android.graphics.Bitmap source,
int requireWidth,
int requireHeight)
source - 被放大或缩小的bitmaprequireWidth - 指定放大或缩小的宽度requireHeight - 指定放大或缩小的高度public static android.graphics.Bitmap createCircleImage(android.graphics.Bitmap source,
int min)
source - 被绘画的bitmapmin - 圆的直径public static android.graphics.Bitmap createCircleImage(android.content.Context context,
android.graphics.Bitmap bitmap)
bitmap - 传入Bitmap对象