转自:http://www.eoeandroid.com/redirect.php?tid=308&goto=lastpost
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout linLayout = new LinearLayout(this);
// 加载需要操作的图片,这里是eoeAndroid的logo图片
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
// 获取这个图片的宽和高
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
// 定义预转换成的图片的宽度和高度
int newWidth = 200;
int newHeight = 200;
// 计算缩放率,新尺寸除原始尺寸
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
// 旋转图片 动作
matrix.postRotate(45);
// 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,
height, matrix, true);
// 将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
// 创建一个ImageView
ImageView imageView = new ImageView(this);
// 设置ImageView的图片为上面转换的图片
imageView.setImageDrawable(bmd);
// 将图片居中显示
imageView.setScaleType(ScaleType.CENTER);
// 将ImageView添加到布局模板中
linLayout.addView(imageView, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// 设置为本activity的模板
setContentView(linLayout);
}
2
分享到:
相关推荐
android bitmap outofMemory 用来解决android中常见的bitmap outOfMemory
android Bitmap相关知识介绍~~~
Android bitmap Android Bitmap相关
Android Bitmap.getPixels的正确理解演示源码,参考文章《Android Bitmap入门:getPixels的正确理解》
ANDROIDBITMAP内存限制OOM,OUTOFMEMORY.pdf
android中对Bitmap图片设置任意角为圆角
Android不支持将Bitmap转换成单色的Bmp图片,所以参考Bmp格式说明,自己写了一个转换类。亲测有效!!!
Android上解析24位深度Bitmap文件示例
Android图片Bitmap和字符串String之间相互转换的工具类,外加项目代码,封装好的,直接可以用,
android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....
Android中压缩bitmap的工具类,用于压缩bitmap图片用,适用于图片体积过大而同时显示等对图片质量要求不大的场景
这个 Demo 给出了 Android 上处理图片的通用方法,包括图片缓存,加载大图片的方法等。
android bitmap通过byte数组以流的形式创建,自己加了进度条,看起来稍微好点
代码是关于bitmap图形特效处理的。有黑白特效、底片特效、浮雕特效、模糊特效、锐化特效、怀旧特效。
主要介绍了Android 实现把bitmap图片的某一部分的颜色改成其他颜色,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
NULL 博文链接:https://chen592969029.iteye.com/blog/749100
Android中bitmap转化成string格式的工具类,主要用于联网操作传递数据情境中
Bitmap bitmap = BitmapFactory.decodeFile(imageFile, opts); 设置inJustDecodeBounds为true后,decodeFile并不分配空间,但可计算出原始图片的长度和宽度,即opts.width和opts.height。有了这两个参数,再通过...
android 游戏开发入门指南,英文版本。
在Android编程中有时候需要对图片做特殊的处理,比如将图片做出黑白的,或者老照片的效果,有时候还要对图片进行变换,以拉伸,扭曲等等。这些效果在Android中有很好的支持,通过颜色矩阵(ColorMatrix)和坐标变换...