当前位置:编程学习 > wap >>

如何重新设置bimpat的大小?

原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/2244

问题描述:

在我的程序中我需要重新设置 bitmap的大小,设置成imageview的大小,下面的代码报错了,如何改正,重新设置 bitmap的大小?
Bitmap bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), aMatrix, false);
Bitmap.createScaledBitmap(bmp, MyImageview_wt, MyImageview_ht, false);
MyImageview.setImageBitmap(bmp);


解决方案:
使用下面的代码试试:

public static Bitmap resizeBitMapImage1(String filePath, int targetWidth,
            int targetHeight) {
        Bitmap bitMapImage = null;
        // First, get the dimensions of the image
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);
        double sampleSize = 0;
        // Only scale if we need to
        // (16384 buffer for img processing)
        Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
                .abs(options.outWidth - targetWidth);
            if (options.outHeight * options.outWidth * 2 >= 1638) {
            // Load, scaling to smallest power of 2 that'll get it <= desired
            // dimensions
            sampleSize = scaleByHeight ? options.outHeight / targetHeight
                    : options.outWidth / targetWidth;
            sampleSize = (int) Math.pow(2d,
                    Math.floor(Math.log(sampleSize) / Math.log(2d)));
        }
        // Do the actual decoding
        options.inJustDecodeBounds = false;
        options.inTempStorage = new byte[128];
        while (true) {
            try {
                options.inSampleSize = (int) sampleSize;
                bitMapImage = BitmapFactory.decodeFile(filePath, options);
                  break;
            } catch (Exception ex) {
                try {
                    sampleSize = sampleSize * 2;
                } catch (Exception ex1) {
                  }
            }
        }
        return bitMapImage;
    }
--------------------编程问答-------------------- 需要用到的,mark一个 --------------------编程问答-------------------- 很实用的代码 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 这比较难 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 学习学习代码 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 不太好说。。。。 --------------------编程问答-------------------- 这么难啊!! --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 能不能给个全的 --------------------编程问答-------------------- 好 牛 额,,,,。 --------------------编程问答-------------------- 很实用的代码 --------------------编程问答-------------------- 有点看不懂啊 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- henhao  henhao   henhao  --------------------编程问答-------------------- 标记收藏一些 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- 谢谢 支持一下 --------------------编程问答-------------------- 很实用的代码.好东西 --------------------编程问答-------------------- 谢谢 支持一下 --------------------编程问答-------------------- --------------------编程问答-------------------- 好好哈。。。。。。//// --------------------编程问答-------------------- 学习。。。。。。 --------------------编程问答-------------------- 刚好用得上这些,谢谢楼主啊~~~太好了 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 为什么没有解释? --------------------编程问答-------------------- 能帮忙解释一下这些代码吗?非常感谢! --------------------编程问答-------------------- 奖励计划经济学院派在家庭主妇在此时间段你说明理由你 --------------------编程问答-------------------- 感谢分享  辛苦了  先mark以后用到再回来看 --------------------编程问答-------------------- 不错不错 --------------------编程问答-------------------- --------------------编程问答-------------------- 除
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,