zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    css 学习笔记 菜鸟
    html学习 菜鸟
    flask 杂记2
    logging 为全局的日志工具对象添加日志记录器
    flask 框架 转载:https://cloud.tencent.com/developer/article/1465968
    flask 框架 转载:https://cloud.tencent.com/developer/article/1465949
    flask blueprint
    [ZJOI2005]午餐
    [ZJOI2006]皇帝的烦恼
    数位dp小练
  • 原文地址:https://www.cnblogs.com/Anonyme/p/14378447.html
Copyright © 2011-2022 走看看