Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

读取位图的大小和类型

$
0
0

BitmapFactory类提供了一些方法来从不同的资源中创建位图,如decodeByteArray(),decodeFile()和decodeResource()等。我们可以根据自己图片的特点选择最适合的解码方法。这些方法都尝试着为所创建的位图分配内存资源,因此很容易导致OutOfMemory异常。每种方法都提供BitmamFactory.optios类来提供特定的解码选项。当解码时候,为了不让系统分配内存,我们可以设置inJustDecodeBounds为True。设置outWidth,outHeight,outMimeType来避免返回null对象。这种技术允许你在构建图片前期就读取它的大小和类型。

 

BitmapFactory.Options options = new BitmapFactory.Options();
options
.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;

 

作者:ltl451011 发表于2013-4-26 13:44:06 原文链接
阅读:0 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>