zoukankan      html  css  js  c++  java
  • Google glass GDK

    网上转的都太不靠谱了 = = 在一个MP3播放器里面挖了出来,用时就用上了~

     1     public static Bitmap getAlbumArtWork(String filePath) {
     2         try {
     3             MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
     4             metaRetriver.setDataSource(filePath);
     5             byte[] album = metaRetriver.getEmbeddedPicture();
     6             if (album != null) {
     7                 BitmapFactory.Options opts = new BitmapFactory.Options();
     8                 opts.inJustDecodeBounds = true;
     9                 BitmapFactory.decodeByteArray(album, 0, album.length, opts);
    10                 opts.inSampleSize = calculateInSampleSize(opts);
    11                 opts.inJustDecodeBounds = false;
    12                 return BitmapFactory.decodeByteArray(album, 0, album.length, opts);
    13             }
    14             return null;
    15         } catch (Exception e) {
    16             return null;
    17         }
    18     }   
    19     public static int calculateInSampleSize(BitmapFactory.Options options) {
    20         // Raw height and width of image
    21         final int height = options.outHeight;
    22         final int width = options.outWidth;
    23         int inSampleSize = 1;
    24         //Our height and width will always be the same since all glass has the same resolution, for now...
    25         if (height > 360 || width > 640) {
    26             final int halfHeight = height / 2;
    27             final int halfWidth = width / 2;
    28             // Calculate the largest inSampleSize value that is a power of 2 and keeps both
    29             // height and width larger than the requested height and width.
    30             while ((halfHeight / inSampleSize) > 360 && (halfWidth / inSampleSize) > 640) {
    31                 inSampleSize *= 2;
    32             }
    33         }
    34 
    35         return inSampleSize;
    36     }
  • 相关阅读:
    周末给女友讲了遍加密算法,没想到...
    gradle执行打包并导出Apk到指定文件夹
    功能算法
    位运算之异或运算
    禁止ViewPager滑动
    macOS 去掉系统软件更新红点提示
    【转】Kotlin的inline内联函数
    Android Gradle Plugin v3.6.0/3.6.1 构建Bug
    IntelliJ IDEA UML插件
    【LeetCode 1. Two Sum】
  • 原文地址:https://www.cnblogs.com/ch3rry/p/3871387.html
Copyright © 2011-2022 走看看