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     }
  • 相关阅读:
    不同长度的数据进行位运算
    Linux的sleep()和usleep()的使用和区别
    linux inode已满解决方法
    Debian 系统修改语言设置成英文
    IIS设置问题
    Ajax实现跨域访问的三种方法
    HTML--备忘点
    C#基础---值类型和引用类型
    dapper.net框架使用随笔
    WebService的搭建,部署,简单应用和实体类结合使用
  • 原文地址:https://www.cnblogs.com/ch3rry/p/3871387.html
Copyright © 2011-2022 走看看