• bitmap生产缩略图


    Android BitMap数据源生产缩略图 
    /**
    * 生成缩略图
    * 缩略图是将原图等比压缩,压缩后宽、高中较小的一个等于198像素
    */
    private Bitmap getThumb(Bitmap bm){
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm .compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] bitmapByte = stream.toByteArray();

    final BitmapFactory.Options options = new BitmapFactory.Options();
    int reqWidth, reqHeight, width = bm.getWidth(), height = bm.getHeight();
    if (width > height){
    reqWidth = 240;
    reqHeight = (reqWidth * height)/width;
    }else{
    reqHeight = 160;
    reqWidth = (width * reqHeight)/height;
    }
    int inSampleSize = 1;
    if (height > reqHeight || width > reqWidth) {
    final int halfHeight = height / 2;
    final int halfWidth = width / 2;
    while ((halfHeight / inSampleSize) > reqHeight
    && (halfWidth / inSampleSize) > reqWidth) {
    inSampleSize *= 2;
    }
    }
    options.inSampleSize = inSampleSize;
    options.inJustDecodeBounds = false;
    Matrix mat = new Matrix();
    Log.d(TAG, "data.length========"+bitmapByte.length);
    Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapByte, 0, bitmapByte.length, options);
    Log.d(TAG, "klx====bitmap.getWidth()===="+bitmap);
    return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mat, true);
    }
  • 相关阅读:
    吴恩达深度学习作业
    @Resource
    Hadoop 大数据平台常用组件端口号汇总
    HDFS读写分析
    HDFS基础之NN、SNN、DN
    teamviewer早期版本下载链接
    linux权限说明
    关于Mac VMFusion Centos7虚拟机网络的配置
    mysql开启远程授权
    Java 空值判断的工具类
  • 原文地址:https://www.cnblogs.com/Anonyme/p/14378447.html
Copyright © 2020-2023  润新知