android图片的缩放
2011-07-19 19:57
260 查看
import android.app.Activity; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
public class bitmaptest extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");
LinearLayout linLayout = new LinearLayout(this);
// 加载需要操作的图片,这里是eoeAndroid的logo图片
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.eoe_android);
//获取这个图片的宽和高
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);
}
}
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
public class bitmaptest extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTitle("eoeAndroid教程: 缩放和旋转图片 -by:IceskYsl");
LinearLayout linLayout = new LinearLayout(this);
// 加载需要操作的图片,这里是eoeAndroid的logo图片
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.eoe_android);
//获取这个图片的宽和高
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);
}
}
相关文章推荐
- Android通过手势(多点)缩放和拖拽图片
- Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)
- android 两点缩放图片
- Android ImageView 图片等比缩放问题
- Android开发之imageView图片按比例缩放的实现方法
- android 图片缩放抗锯齿
- Android开发之--Android实现对图片的缩放、剪切、旋转、存储
- Android 图片处理之-->android.graphics.Camera实现图像的旋转、缩放
- Android实现图片缩放与旋转
- Android 调用相册 拍照 实现系统控件缩放 切割图片 .
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- Android 缩放图片
- android触摸 图片的缩放和放大 带着图片在屏幕上游走
- Android 手势检测实战 打造支持缩放平移的图片预览效果(下)
- Android 多点触控,多张图片拖拽,缩放,旋转
- Android 拼接多张图片(拖拽,缩放)
- android 实现 波纹效果+图片左右无限滑动缩放效果
- Android自定义控件ImageViwe(三)——随手指进行图片的缩放
- Android imageView图片按比例缩放
- Android之matrix类控制图片的旋转、缩放、移动