android 实用的Bitmap处理函数
来源:互联网 发布:独立域名邮箱 编辑:程序博客网 时间:2024/06/05 20:45
这里给出一个将图片放大、缩小的处理函数:
/**
* bgimage 需要处理的图片
* newWidth 、newHeight 这张图片处理后的宽高,这里newWidth 和 newHeight 其有效值是>= 0; 当其中一个值为0时候,表示按等宽* 高比来放大或是缩小。如果两个值都为0,则不进行放大缩小。
* recy_the_bitmap 其值是一个boolean 值。其作用是:对bgimage 这张图片处理完成后是否回收其资源,对于手机这样的移动设备开发,其资源非常有限,这个是必须的。
**/
public static Bitmap zoomImage(Bitmap bgimage, int newWidth, int newHeight, boolean recy_the_bitmap) { // 记得函数声明为static
int width;
int height;
Bitmap bitmap_mage = null;
if(bgimage != null && !(newWidth==0 && newHeight==0))
{
float scaleWidth = 1.0f;
float scaleHeight = 1.0f;
width = bgimage.getWidth();
height = bgimage.getHeight();
Matrix matrix = new Matrix();
if(newWidth > 0)
{
scaleWidth = ((float) newWidth) / width;
}
if(newHeight > 0)
{
scaleHeight = ((float) newHeight) / height;
}
if(scaleWidth == 1.0f)
{
scaleWidth = scaleHeight;
}
if(scaleHeight == 1.0f)
{
scaleHeight = scaleWidth;
}
matrix.postScale(scaleWidth, scaleHeight);
bitmap_mage = Bitmap.createBitmap(bgimage, 0, 0, width, height,
matrix, true);
}
if(bitmap_mage != null)
{
if(recy_the_bitmap)
{// 回收资源
bgimage.recycle();
bgimage = null;
}
return bitmap_mage;
}
else
{
return bgimage;
}
}
有什么不妥的地方请大家指出,
- android 实用的Bitmap处理函数
- Android Bitmap图片的处理
- Android 缩放bitmap的函数
- (android图像处理)android之bitmap各种常用函数
- Android的Bitmap处理大图片解决方法
- Android的图像处理类Bitmap
- Android的图像处理类Bitmap
- Android中常用的bitmap处理方法
- Android有效的处理Bitmap,减少内存
- Android之图片Bitmap的特殊处理
- Android对图片的处理(Bitmap)
- Android处理Bitmap的一些方法(多)
- Android对Bitmap处理的工具类
- Android一些实用的函数
- 在非UI线程处理Bitmap(实用)
- android 处理bitmap
- Android Bitmap处理
- Android bitmap图片处理
- @ManyToOne
- python 生成随机密码工具
- 【系统信息获取】9,获取主机名
- 扩展Event 让事件带参
- 稀疏学习
- android 实用的Bitmap处理函数
- Oracle面试题
- EBS OAF开发中如何在form上调用OAF页面并传递参数给OAF页面
- 几何 入门题 UVA 11800 - Determine the Shape
- csdn 代码样式 代码高亮 代码风格
- 可变参数函数
- 稀疏表示step by step
- 数字图像的处理
- Pro Android学习笔记(七六):服务(1):local和remote