zoukankan      html  css  js  c++  java
  • Android BitmapFactory.Options

    public Bitmap inBitmap 如果设置,解码选项“对象的方法,采取将尝试重用这个位图加载内容时。
    public int inDensity 使用的位图的象素密度。
    public boolean inDither 如果抖动是真实的,解码器将尝试到抖动的解码图像。
    public boolean inInputShareable 此字段一起选择inPurgeable。
    public boolean inJustDecodeBounds 如果设置为true,解码器将返回null(位图),但输出...
    public boolean inMutable 如果设置,解码方法总是返回一个可变的位图,而不是一个一成不变的。
    public boolean inPreferQualityOverSpeed 如果inPreferQualityOverSpeed​​设置为true,解码器将尝试解码重建图像以较高的质量,甚至不惜牺牲的解码速度。
    public Bitmap.Config inPreferredConfig 如果非空,这个内部配置解码器将尝试解码。
    public boolean inPurgeable 如果设置为true,则生成的位图将分配给它的像素,这样它们可以被清除,如果系统需要回收内存。
    public int inSampleSize 如果设置为> 1的值,要求的解码器,以进行子采样的原始图像,返回一个较小的图像,以节省内存。
    public boolean inScaled 当设置了这个标志,如果夏季风和inTargetDensity不为0,位图将进行调整,以符合inTargetDensity时加载,而不是依赖它每次被画到画布上的图形系统结垢。
    public int inScreenDensity 正在被使用的实际的屏幕的像素密度。
    public int inTargetDensity 目的地的像素密度的这个位图将被吸引到。
    public byte[] inTempStorage 温度存储用于解码。
    public boolean mCancel 表明,取消已经对这个对象调用的标志。
    public int outHeight 位图高度,设置独立的状态inJustDecodeBounds。
    public String outMimeType 如果知道,这个字符串解码后的图像的mime类型设置为。
    public int outWidth 位图的宽度,设置独立的状态inJustDecodeBounds。

    inJustDecodeBounds设为true,BitmapFactory.decodeFile(String path, Options opt)并不会真的返回一个Bitmap给你,它仅仅会把它的宽,高取回来给你,就不会占用太多的内存。

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap bmp = BitmapFactory.decodeFile(path, options);
        /* 这里返回的bmp是null */ 

    宽和高:options.outWidth 和 options.outHeight

    获取图片指定大小的缩略图:

        /* 计算得到图片的高度 */
        /* 这里需要主意,如果你需要更高的精度来保证图片不变形的话,需要自己进行一下数学运算 */
        int height = options.outHeight * 200 / options.outWidth;
        options.outWidth = 200;
        options.outHeight = height; 
        /* 这样才能真正的返回一个Bitmap给你 */
        options.inJustDecodeBounds = false;
        Bitmap bmp = BitmapFactory.decodeFile(path, options);
        image.setImageBitmap(bmp); 

    要节约内存,还需要用到BitmapFactory.Options这个类里的 inSampleSize 这个成员变量:

        inSampleSize = options.outWidth / 200; 
      另外,为了节约内存我们还可以使用下面的几个字段:
        options.inPreferredConfig = Bitmap.Config.ARGB_4444;    // 默认是Bitmap.Config.ARGB_8888
        /* 下面两个字段需要组合使用 */
        options.inPurgeable = true;
        options.inInputShareable = true; 
  • 相关阅读:
    hbase shell-namespace(命名空间指令)
    hbase shell-general(常规指令)
    hbase shell概述
    Codeforces Round #412 div2 ABCD
    Educational Codeforces Round 19
    CSU 1786 莫队+KDTree
    cdq分治入门and持续学习orz
    VK Cup 2017
    HRBUST 2072 树上求最大异或路径值
    UvaLive 5811 概率DP
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4206070.html
Copyright © 2011-2022 走看看