- 浏览: 334048 次
- 性别:
- 来自: 安徽
文章分类
最新评论
-
secally:
楼主可以上传个例子吗,谢谢,我咋跑不起来,,eclipse不是 ...
Android自动打包、签名、优化、上传ANT脚本 -
secally:
请问下执行命令是啥,ant release 还是?麻烦指教谢谢 ...
Android自动打包、签名、优化、上传ANT脚本 -
trp1022:
好牛啊
程序员不能不通文史 -
sunny78117:
谢谢,写得好
Android bitmap优化 -
futurebp:
这是什么类型的脚本啊?
Android自动打包、签名、优化、上传ANT脚本
Android bitmap优化
- 博客分类:
- Android
直接使用ImageView显示bitmap会占用较多资源,特别是图片较大的时候,可能导致崩溃。
使用BitmapFactory.Options设置inSampleSize, 这样做可以减少对系统资源的要求。
属性值inSampleSize表示缩略图大小为原始图片大小的几分之一,即如果这个值为2,则取出的缩略图的宽和高都是原始图片的1/2,图片大小就为原始大小的1/4。
Options中有个属性inJustDecodeBounds,SDK中是这么说的
If set to true, the decoder will return null (no bitmap), but the out... fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
通过设置inJustDecodeBounds为true,获取到outHeight(图片原始高度)和outWidth(图片的原始宽度),然后计算一个inSampleSize(缩放值)
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ImageView android:id="@+id/imageview" android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="center" /> </LinearLayout>
import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.ImageView; import android.widget.Toast; public class AndroidImage extends Activity { private String imageFile = "/sdcard/AndroidSharedPreferencesEditor.png"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView myImageView = (ImageView)findViewById(R.id.imageview); //Bitmap bitmap = BitmapFactory.decodeFile(imageFile); //myImageView.setImageBitmap(bitmap); Bitmap bitmap; float imagew = 300; float imageh = 300; BitmapFactory.Options bitmapFactoryOptions = new BitmapFactory.Options(); bitmapFactoryOptions.inJustDecodeBounds = true; bitmap = BitmapFactory.decodeFile(imageFile, bitmapFactoryOptions); int yRatio = (int)Math.ceil(bitmapFactoryOptions.outHeight/imageh); int xRatio = (int)Math.ceil(bitmapFactoryOptions.outWidth/imagew); if (yRatio > 1 || xRatio > 1){ if (yRatio > xRatio) { bitmapFactoryOptions.inSampleSize = yRatio; Toast.makeText(this, "yRatio = " + String.valueOf(yRatio), Toast.LENGTH_LONG).show(); } else { bitmapFactoryOptions.inSampleSize = xRatio; Toast.makeText(this, "xRatio = " + String.valueOf(xRatio), Toast.LENGTH_LONG).show(); } } else{ Toast.makeText(this, "inSampleSize = 1", Toast.LENGTH_LONG).show(); } bitmapFactoryOptions.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeFile(imageFile, bitmapFactoryOptions); myImageView.setImageBitmap(bitmap); } }
发表评论
-
抓取Android WebView截屏
2011-08-19 21:33 7577一般使用setDrawingCacheEnabled(true ... -
Android模拟器更改分辨率后 无法取得分辨率问题
2011-05-11 21:06 2782在PC上更改模拟器分辨率为480*800 (如果你的PC界面 ... -
获取屏幕硬件分辨率方法 收藏
2011-05-11 16:28 1875TextView tv=(TextVie ... -
Bytecode for the Dalvik VM
2011-05-10 22:35 1313http://www.netmite.com/android/ ... -
Android DEX反编译后部分代码解析
2011-05-10 22:07 3850一个private 方法 private Stri ... -
反编译并且修改Android APK包
2011-05-10 16:57 3051為了某個實驗的動機,我們評估反編譯 Android ... -
Android Ant编译时候进行混淆
2010-10-18 13:49 3800版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
自定义Ant Task
2010-09-13 17:58 2958版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
Android自动打包、签名、优化、上传ANT脚本
2010-07-26 16:51 13923版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
Android自定义含有CheckBox的Adapter遇到的问题
2010-06-23 13:48 4078版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
QR code类库
2010-06-03 23:11 2283Google code发现的好东西。 QR code 类库 ... -
Android QQ,一个WEBOS APP诞生!!(两个QQ对比!)
2010-04-10 12:05 1838请看这个大哥的言论 http://linuxtoy.or ... -
Android 、BlackBerry 文本对齐方式对比
2010-02-22 13:11 1769版权所有,欢迎转载,转载请注明 : SinFrancis h ... -
教你如何开关Android的APN网络
2010-01-08 11:36 5962版权所有,转载请注明来自Mobile Developer (h ... -
史上最强NDK入门项目实战
2009-10-10 13:29 2659以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
使用TimerTask控制ProgressBar
2009-10-10 13:21 1037以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
自定义List布局
2009-10-10 13:19 1851以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
重画Progressbar的进度
2009-10-10 13:15 1905以下内容Sinfrancis版权所有,专注请注明来自 htt ... -
谈谈Android中文短信的实现
2009-10-10 13:13 2136似 乎Google在推出G1时 ... -
模拟器互发短信
2009-10-10 13:11 1249以下内容Sinfrancis版权所有,专注请注明来自 htt ...
相关推荐
Android Bitmap详解及Bitmap的内存优化 一、Bitmap: Bitmap是Android系统中的图像处理的最重要类之一。用它可以获取图像文件信息,进行图像剪切、旋转、缩放等操作,并可以指定格式保存图像文件。 常用方法: ...
高效加载 Bitmap BitMapFactory 提供了四类方法: decodeFile,decodeResource,decodeStream 和 decodeByteArray 分别用于从文件系统,资源,输入流以及字节数组中加载出一个 Bitmap 对象。 高效加载 Bitmap 很简单,即...
这里就有疑问了,Android系统有自己的垃圾回收机制,可以不定期的回收掉不使用的内存空间,当然也包括Bitmap的空间。那为什么还需要这个方法呢? Bitmap类的构造方法都是私有的,所以开发者不能直接new出一个Bitmap...
在Android开发过程中,Bitmap往往会给开发者带来一些困扰,因为对Bitmap操作不慎,就容易造成OOM(Java.lang.OutofMemoryError – 内存溢出),本篇博客,我们将一起探讨Bitmap的性能优化。 为什么Bitmap会导致OOM? 1...
Android 内存 OOM 优化和治理,Android 内存泄漏原因详解与应对措施,Android 中的 Bitmap 使用详解,Android 中的 Bitmap 内存治理和优化详解,Android 内存分析命令详解,Java内存模型。Android 内存 OOM 优化和...
安卓在加载大图的时候经常会出现oom的错误,给大家分享我的一些处理经验。 这个是优化后的版本。
Android性能优化(七)Bitmap内存压缩示例源码
Camera onPreview中byte[] 转换为Bitmap 在录像时设置了YV12要保存图片时 YV12或者NV12时要转换时所用的工具的优化
Google 官方 Android DisplayBimaps的优化事例,博客链接http://blog.csdn.net/chivalrousman/article/details/51553114
android-tao-bitmap Android位图库。 变形金刚(制作为Builder)位图-旋转,翻转,调整大小,缩放,裁剪位图。 存在内存优化(默认情况下使用缓存文件)。 从视图转换位图。 使用遮罩创建形状的位图。
Bitmap压缩技术 主流android图片优化技术
Android内存优化是我们性能优化工作中比较重要的一环,这里其实主要包括两方面的工作: 1、优化RAM,即降低运行时内存。这里的目的是防止程序发生OOM异常,以及降低程序由于内存过大被LMK机制杀死的概率。另一方面,...
Android--从系统Camera和Gallery获取图片优化http://www.cnblogs.com/plokmju/p/android_BitmapRecycle.html
因此,改用先通过BitmapFactory.decodeStream方法,创建出一个bitmap,再将其设为ImageView的source,decodeStream最大的秘密在于其直接调用JNI>>nativeDecodeAsset()来完成decode,无需再使用java层的createBitmap...
本书是一本Android进阶类书籍,采用理论、源码和实践相结合的... 15.1.5 ListView和Bitmap优化 501 15.1.6 线程优化 501 15.1.7 一些性能优化建议 501 15.2 内存泄露分析之MAT工具 502 15.3 提高程序的可维护性 506