首页 > 其他 > 详细

多媒体编程

时间:2015-12-22 00:56:50      阅读:333      评论:0      收藏:0      [点我收藏+]

*文本、图片、音频、视频都属于多媒体

  *图片

 

 


    public void click(View v){
     //解析图片时需要使用到的参数都封装在这个对象里了
     Options opt = new Options();
     //不为像素申请内存,只获取图片宽高
     opt.inJustDecodeBounds = true;
     BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
     //拿到图片宽高
     int imageWidth = opt.outWidth;
     int imageHeight = opt.outHeight;
     
     Display dp = getWindowManager().getDefaultDisplay();
     //拿到屏幕宽高
  int screenWidth = dp.getWidth();
     int screenHeight = dp.getHeight();
     
     //计算缩放比例
     int scale = 1;
     int scaleWidth = imageWidth / screenWidth;
     int scaleHeight = imageHeight / screenHeight;
     if(scaleWidth >= scaleHeight && scaleWidth >= 1){
      scale = scaleWidth;
     }
     else if(scaleWidth < scaleHeight && scaleHeight >= 1){
      scale = scaleHeight;
     }
     
     //设置缩放比例
     opt.inSampleSize = scale;
     opt.inJustDecodeBounds = false;
     Bitmap bm = BitmapFactory.decodeFile("sdcard/dog.jpg", opt);
     
     ImageView iv = (ImageView) findViewById(R.id.iv);
     iv.setImageBitmap(bm);
    }

多媒体编程

原文:http://www.cnblogs.com/myzzx/p/5065256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!