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. 文件夹无法访问怎样解决?
  2. 漫画:什么是 “代理模式” ?
  3. 漫画:设计模式中的 “观察者模式”
  4. 这个17岁的***天才,破解了第一代iPhone!
  5. 漫画设计模式:什么是 “装饰器模式” ?
  6. 什么是 “马太效应” ?
  7. Golang 之禅
  8. 安全星球|盘点最新国内外网络安全资讯(5月1
  9. 网络 基础1
  10. 同为Chromium浏览器,Edge却被“特别关照”