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;/** * This example shows how to resize an image * @author FaYnaSoft Labs * */public class Main extends Activity {@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);LinearLayout linearLayout = new LinearLayout(this);Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);int width = bitmap.getWidth();int height = bitmap.getHeight();int newWidth = 640;int newHeight = 480;float scaleWidth = ((float) newWidth) / width;float scaleHeight = ((float) newHeight) / height;Matrix matrix = new Matrix();matrix.postScale(scaleWidth, scaleHeight);// create the new Bitmap objectBitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,height, matrix, true);BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);ImageView imageView = new ImageView(this);imageView.setImageDrawable(bmd);imageView.setScaleType(ScaleType.CENTER);linearLayout.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));setContentView(linearLayout);}}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android开发之Android是什么
  2. Android我还可以相信你多少系列文章三之
  3. 月入3W的高级Android架构师都具备哪些能
  4. Android(安卓)Studio 1.0 (稳定版) 完全
  5. 4.Android(安卓)打包时出现的Android(安
  6. 【动态加载】Android动态加载:简单加载模
  7. 【Android(安卓)Training - 00】Google A
  8. 在Android(安卓)Studio中使用Lambda表达
  9. Android面试系列文章2018之Android部分Co
  10. Android开发