由于android软件的显示控件上要求长度超过一定的数值就截取并加省略号,所以写了这个方法:

    package com.eoeandroid.demo.testcode;    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);        }    }

更多相关文章

  1. android studio上imageloader初探
  2. 2011.10.09——— android ImageView放大缩小(2)
  3. android内存溢出的解决方法(转)
  4. Android实用视图动画及工具系列之九:漂亮的图片选择器,高性能防崩
  5. 调用Android相机拍照的问题
  6. android 拍照或选择图片的实现方式//AtlerDialog的多种样式
  7. 自定义View实现图片的绘制、旋转、缩放
  8. Android(安卓)手势检测
  9. Android(安卓)ImageView.ScaleType详解

随机推荐

  1. Android学习网站
  2. Android:Android.bat批处理命令
  3. androidannotations 在android studio中
  4. Android利用tcpdump抓包
  5. Android(安卓)SDK 25.2.3 移除了 android
  6. android的常用控件总结【安卓入门五】
  7. How to Use OpenCV in Android(安卓)Stud
  8. 我的Android进阶之旅------>Android视频
  9. Tip of the Day(Android(安卓)Studio)
  10. android listview 设置点击效果selector