public static Bitmap createScaledBitmap(
来源:互联网 发布:手机麻将软件开发商 编辑:程序博客网 时间:2024/05/24 16:14
public static enum ScalingLogic {
CROP, FIT,SCALE_CROP
}
public static Rect calculateSrcRect(int srcWidth, int srcHeight, int dstWidth, int dstHeight,
ScalingLogic scalingLogic) {
if (scalingLogic == ScalingLogic.CROP) {
final float srcAspect = (float)srcWidth / (float)srcHeight;
final float dstAspect = (float)dstWidth / (float)dstHeight;
if (srcAspect > dstAspect) {
final int srcRectWidth = (int)(srcHeight * dstAspect);
final int srcRectLeft = (srcWidth - srcRectWidth) / 2;
return new Rect(srcRectLeft, 0, srcRectLeft + srcRectWidth, srcHeight);
} else {
final int srcRectHeight = (int)(srcWidth / dstAspect);
final int scrRectTop = (int)(srcHeight - srcRectHeight) / 2;
return new Rect(0, scrRectTop, srcWidth, scrRectTop + srcRectHeight);
}
} else {
return new Rect(0, 0, srcWidth, srcHeight);
}
}
public static Rect calculateDstRect(int srcWidth, int srcHeight, int dstWidth, int dstHeight,
ScalingLogic scalingLogic) {
if (scalingLogic == ScalingLogic.FIT) {
final float srcAspect = (float)srcWidth / (float)srcHeight;
final float dstAspect = (float)dstWidth / (float)dstHeight;
if (srcAspect > dstAspect) {
return new Rect(0, 0, dstWidth, (int)(dstWidth / srcAspect));
} else {
return new Rect(0, 0, (int)(dstHeight * srcAspect), dstHeight);
}
} else {
return new Rect(0, 0, dstWidth, dstHeight);
}
}
public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight,
ScalingLogic scalingLogic) {
if(unscaledBitmap ==null)
return null;
Rect srcRect = calculateSrcRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(),
dstWidth, dstHeight, scalingLogic);
Rect dstRect = calculateDstRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(),
dstWidth, dstHeight, scalingLogic);
Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(),
Config.ARGB_8888);
Canvas canvas = new Canvas(scaledBitmap);
canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG|Paint.ANTI_ALIAS_FLAG));
return scaledBitmap;
}
public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, float zoomFactor,
ScalingLogic scalingLogic) {
if(unscaledBitmap ==null)
return null;
int dstWidth = (int)(zoomFactor*unscaledBitmap.getWidth());
int dstHeight = (int)(zoomFactor*unscaledBitmap.getHeight());
return createScaledBitmap(unscaledBitmap,dstWidth,dstHeight,scalingLogic);
}
- public static Bitmap createScaledBitmap(
- public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight,
- public static Bitmap getMutableBitmap(Bitmap bitmap)
- Bitmap.createScaledBitmap的陷阱
- Bitmap.createScaledBitmap的陷阱
- public static Bitmap zoomIn(Bitmap bitmap, int maxW, int maxH)
- 【bug】:Bitmap.createScaledBitmap不能满屏
- 关于BItmap.createScaledBitmap释放内存引发的bug
- public static
- static public与public static
- public, public readonly, public static, public const
- Private Static & Public Static 区别
- createScaledBitmap参数
- public,protected,private,static
- public static String utf8Byte2String
- public static void longToAscString
- public static Long ascByteToLong
- final static public---Java
- HttpRequest下载图片,判断图片类型
- windows搭建android开发环境
- phoneGap API调用摄像头并上传图片
- 秋雨寄相思
- jquerymobile 动态加载表单内容后怎么重新渲染?
- public static Bitmap createScaledBitmap(
- input button的行高在FF下的显示问题
- tomcat知识点
- mysql优化之使用索引
- VLC doc
- C++之运算符重载(2)
- word add-in 卸载时如何清除自定义的按钮和菜单
- 初步了解Statement和PreparedStatement之间的区别
- ubuntu安装jdk,ubuntu设置java环境变量,ubuntu安装jdk,ubuntu设置java环境变量,ubuntu安装 jdk,ubuntu设置java环境变量