图片比例缩放以及bitMap转BitmapDrawable
来源:互联网 发布:spark连接巨杉数据库 编辑:程序博客网 时间:2024/05/22 03:07
- 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 {
- @Override
- public 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 object
- Bitmap 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);
- }
- }
转自:http://wang-peng1.iteye.com/blog/669532
- 图片比例缩放以及bitMap转BitmapDrawable
- Android如何缩放图片以及Drawable转Bitmap方法
- Android Bitmap转换以及图片的缩放
- 详解Bitmap使用,以及BitmapDrawable和BitmapFactory
- 成比例缩放图片
- 安比例缩放图片
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 图片等比例缩放
- 等比例缩放图片
- 等比例缩放图片
- 等比例缩放图片
- 图片等比例缩放
- 图片比例缩放控制
- 等比例图片缩放
- 编译android遇到java虚拟机堆内存不够的问题 java.lang.OutOfMemoryError: GC overhead limit exceeded 解决方法
- 简单实现MFC ListControl 点击列头排序
- delphi中单独编译pas生成dcu文件
- 一种 去掉复制代码行号 的方法
- 【记】一年之计在于春
- 图片比例缩放以及bitMap转BitmapDrawable
- Delphi第三方组件安装DCU.PAS.DPK.BPL.ActiveX控件
- jboss修炼篇----创建jboss虚拟目录
- hello world
- 学生资助计划
- 一个Java程序员应该掌握的10项技能
- UISegmentedControl
- 基于SAAJ的Web服务----(三)从SOAP消息中提取内容
- 一道数模题(扑克牌中求期望)