BitmapFactory.Options
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inSampleSize = ;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
imv.setImageBitmap(bmp);
上面的代码使图片变成原来的1/8.\
//imv = (ImageView) findViewById(R.id.ReturnedImageView);
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();
try
{
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().
openInputStream(imageFileUri), null, bmpFactoryOptions); int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)dh);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)dw); Log.v("HEIGHRATIO", ""+heightRatio);
Log.v("WIDTHRATIO", ""+widthRatio); if (heightRatio > && widthRatio > )
{
bmpFactoryOptions.inSampleSize = heightRatio > widthRatio ? heightRatio:widthRatio;
}
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory.decodeStream(getContentResolver().
openInputStream(imageFileUri), null, bmpFactoryOptions);
returnedImageView.setImageBitmap(bmp);
}
catch (FileNotFoundException e)
{
Log.v("ERROR", e.toString()); }
上面的代码让图片根据窗口大小改变
bmpFactoryOptions.inJustDecodeBounds = true;
这一行让代码只解码图片的Bounds
BitmapFactory.Options的更多相关文章
- Android学习笔记之BitmapFactory.Options实现图片资源的加载...
PS:小项目总算是做完了...历经20多天...素材,设计,以及实现全由自己完成...心力憔悴啊...该写写博客记录一下学习到的东西了... 学习内容: 1.使用BitmapFactory.Optio ...
- android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩
网上有很多说是因为没有采用HttpClient造成的,尼玛,我改成了HttpClient 请求图片之后还是会出现SkImageDecoder::Factory returned null, 但是直接使 ...
- 【转】BitmapFactory.Options
BitmapFactory.Options这个类的信息:http://developer.android.com/reference/android/graphics/BitmapFactory.Op ...
- android之BitmapFactory.Options的使用
怎样获取图片的大小? 首先我们把这个图片转成Bitmap,然后再利用Bitmap的getWidth()和getHeight()方法就可以取到图片的宽高了. 新问题又来了,在通过BitmapFactor ...
- Android实战简易教程-第九枪(BitmapFactory.Options对资源图片进行缩放)
我们知道,我们编写的应用程序都是有一定内存限制的.程序占用了过高的内存就easy出现OOM(OutOfMemory)异常.因此在展示高分辨率图片的时候,最好先将图片进行压缩,压缩后的图片大小应该和用来 ...
- BitmapFactory.Options.inSampleSize 的使用方法
BitmapFactory.decodeFile(imageFile); 用BitmapFactory解码一张图片时.有时会遇到该错误. 这往往是因为图片过大造成的. 要想正常使用,则须要分配更少的内 ...
- Android BitmapFactory.Options
public Bitmap inBitmap 如果设置,解码选项“对象的方法,采取将尝试重用这个位图加载内容时. public int inDensity 使用的位图的象素密度. public boo ...
- BitmapFactory.Options对图片进行缩放
package com.pingyijinren.helloworld.activity; import android.graphics.Bitmap; import android.graphic ...
- Android使用BitmapFactory.Options解决加载大图片内存溢出问题
由于Android对图片使用内存有限制,若是加载几兆的大图片便内存溢出.Bitmap会将图片的所有像素(即长x宽)加载到内存中,如果图片分辨率过大,会直接导致内存溢出(java.lang.OutOfM ...
随机推荐
- AngularJS入门之数据绑定
本篇我们看一下AngularJS中的数据绑定.虽然我们直到这篇才提到数据绑定,但事实上在前面几篇中我们已经非常熟练的运用AngularJS的数据绑定功能了! ngBind(ng-bind)/ {{ e ...
- “context:include-filter”与“context:exclude-filter”标签作用解释
注意到spring中<context:component-scan>标签中会出现include和exclude的子标签,具体是做什么用的? spring的配置文件与springmvc的配置 ...
- hadoop2.x 异常
运行mr,出现如下异常 需要配置yarn-site.xml中配置如下信息 参考地址: https://issues.apache.org/jira/browse/MAPREDUCE-2983 http ...
- 【树】Convert Sorted Array to Binary Search Tree
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...
- 【链表】Partition List
题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...
- Android版本分布——2017年5月更新
Code Name Version API Level Last month This month Change gingerbread(姜饼) 2.3.3——2.3.7 10 0.9% 1.0% 0 ...
- [转] 用协议分析工具学习TCP/IP
一.前言 目前,网络的速度发展非常快,学习网络的人也越来越多,稍有网络常识的人都知道TCP/IP协议是网络的基础,是Internet的语言,可以说没有TCP/IP协议就没有互联网的今天.目前号称搞网的 ...
- hbase copyTable
参考:https://yq.aliyun.com/articles/176546 执行:hbase org.apache.hadoop.hbase.mapreduce.CopyTable --new. ...
- pcap简单使用和简单解释
数据类型bpf_u_int32实际上就是u_int的一个别名,还有吧bpf_int32实际上就是int的别名.当然这个int是32位的,如果操作系统对int的定义不是4字节,bpf_int32就对应另 ...
- Nodejs学习笔记(七)—Node.js + Express 构建网站简单示例
前言 上一篇学习了一些构建网站会用到的一些知识点:https://www.cnblogs.com/flyingeagle/p/9192936.html 这一篇主要结合前面讲到的知识,去构建一个较为完整 ...