zoukankan      html  css  js  c++  java
  • Android 加载超长大图(长度超过4096)的解决方案和处理办法

    最近工作上发现一个bug,图片加载不出来。显示黑屏,什么也没有,可是图片地址没有问题呀。

    最后查看log发现有个报错

    Bitmap too large to be uploaded into a texture (1445x6459, max=4096x4096)

    意思就是bitmap的长图超长了,大于了4096,。

    最后经过查询发现有两种解决办法。

    一:把bitmap的长度压制4096

        // 利用矩阵并指定宽高
        public static Bitmap resizeImage(Bitmap bitmap, int w, int h) {
            // 原图的bitmap
            Bitmap BitmapOrg = bitmap;
            // 原图的宽高
            int width = BitmapOrg.getWidth();
            int height = BitmapOrg.getHeight();
            // 指定的新的宽高
            int newWidth = w;
            int newHeight = h;
            // 计算的缩放比例
            float scaleWidth = ((float) newWidth) / width;
            float scaleHeight = ((float) newHeight) / height;
            // 用于缩放的矩阵
            Matrix matrix = new Matrix();
            // 矩阵缩放
            matrix.postScale(scaleWidth, scaleHeight);
            // 如果要旋转图片
            // matrix.postRotate(45);
            // 生成新的bitmap
            Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
                    height, matrix, true);
            return resizedBitmap;
        }

    方法二: 把图片分成两截分别在两个ImageView上显示

    bitmap是你的需要截取的图片bitmap

     Bitmap topBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), (int) (bitmap.getHeight() / 2.0f));
                Bitmap bottomBitmap = Bitmap.createBitmap(bitmap, 0, (int) (bitmap.getHeight() / 2.0f), bitmap.getWidth(),
                        bitmap.getHeight() - (int) (bitmap.getHeight() / 2.0f));
                mImageView.setImageBitmap(topBitmap);
                mImageView2.setImageBitmap(bottomBitmap);
  • 相关阅读:
    SLAB
    /proc/vmstat 详解
    swap空间可以有效缓解内存压力
    内存问题排查手段及相关文件介绍
    buddyinfo 内存碎片数据采集
    取得Linux系统的各种统计信息
    HTML的常用总结
    采用jquery同django实现ajax通信
    Django的quarySet
    Django-MySQL数据库使用01
  • 原文地址:https://www.cnblogs.com/niupi/p/11507002.html
Copyright © 2011-2022 走看看