• 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);
    }
  • 相关阅读:
    HDU 5213 分块 容斥
    HDU 2298 三分
    HDU 5144 三分
    HDU 5145 分块 莫队
    HDU 3938 并查集
    HDU 3926 并查集 图同构简单判断 STL
    POJ 2431 优先队列
    HDU 1811 拓扑排序 并查集
    HDU 2685 GCD推导
    HDU 4496 并查集 逆向思维
  • 原文地址:https://www.cnblogs.com/Anonyme/p/14378447.html
Copyright © 2020-2023  润新知