按比例缩放分辨率大的图片

public   class   MainActivity   extends   Activity {

       private   ImageView    iv ;
       private   WindowManager    vm ;
       private   int   height ;
       private   int   width ;
      
       protected   void   onCreate(Bundle savedInstanceState) {
               super .onCreate(savedInstanceState);
            setContentView(R.layout.   activity_main );
            
               iv =(ImageView) findViewById(R.id.   iv );
               //得到屏幕管理者
               vm =(WindowManager)   this .getSystemService(   WINDOW_SERVICE );
            
            Point outSize =   new   Point();
            
            
               //1.得到屏幕的宽和高     getDefaultDisplay():得到屏幕的分辨率
               height =   vm .getDefaultDisplay(). getHeight();
               width =   vm .getDefaultDisplay(). getWidth();
            
            
            
      }
      
      
       /**
       * 显示图片的方法
       */
       public   void   click(View view){
            
       //2.得到图片的宽和高
      BitmapFactory.Options  opts=   new   Options();      //Options代表bitmap的参数
       //不是去真正的解析bitmap而是去解析bitmap的头信息
      opts. inJustDecodeBounds = true ;
      
      BitmapFactory.decodeFile( "/sdcard/IMG_20130627_183247.jp g" ,opts);
      
            int   imgheight=opts.   outHeight ;
            int   imgwidth=opts.   outWidth ;
         
         
            //3.计算缩放比
            int   xscale=imgwidth/   width ;
            int   yscale=imgheight/   height ;
         
            int   scale=1;
         
            if (xscale>yscale){
            scale=xscale;
          }   else {
            scale=yscale;
          }
         
         
          System.   out .println(   "手机宽是:" + width   + "    手机高是:"   + height   );
          System.   out .println(   "图片的宽是:"   +imgwidth+ "图片的高是"   +imgheight);
          System.   out .println(   "宽度比例:" +xscale+ "高度比例:"   +yscale);
          System.   out .println(   "缩放成功,缩放的比例是:"   +scale);
         
         
            //设施位图显示比例,按照比例去解析位图
          opts.   inSampleSize =scale;
          opts.   inJustDecodeBounds =   false ;      //去真正的解析bitmap
            
          Bitmap  bitmap=BitmapFactory.decodeFile( "/mnt/sdcard/Pictures/1.jpg" ,opts);
            iv .setImageBitmap(bitma p);
         
        
         
      }
      
       /**
       * 显示图片信息的方法
       *   @param   view
       */
       public   void   click2(View view){
          try   {
                     //创建exif
                  ExifInterface  exif=   new   ExifInterface( "/mnt/sdcard/Pictures/1.jpg"   );
                  String time = exif.getAttribute(ExifInterface. TAG_DATETIME );
                  String model = exif.getAttribute(ExifInterface. TAG_MODEL   );
                  
                  System.   out .println(   "拍照的时间:"   +time);
                  System.   out .println(   "相机:" +model);
                  
                  
            }   catch   (IOException e) {
                  e.printStackTrace();
            }
            
            
            
      }
      
      

      



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值