主要的代码如下:

     BitmapFactory.Options options = new BitmapFactory.Options();
//图片解析配置
options.inJustDecodeBounds = true;
//获取图片的属性并赋予options
BitmapFactory.decodeResource(getResources(), R.drawable.f1, options);
//获得图片实际宽高
int imgWidth = options.outWidth;
int imgHeight = options.outHeight;
System.out.println("outWidth = " + imgWidth);
System.out.println("outHeight = " + imgHeight);
//获取屏幕大小
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
int windowwidth = windowManager.getDefaultDisplay().getWidth();
int windowheight = windowManager.getDefaultDisplay().getHeight();
System.out.println("width = " + windowwidth);
System.out.println("height = " + windowheight);
//计算缩放
int scale = 1;
int scaleX = imgWidth/windowwidth;
int scaleY = imgHeight/windowheight; if(scaleX>1 && scaleX>scaleY) {
scale = scaleX;
}
if(scaleY>1 && scaleY>scaleX) {
scale = scaleY;
}
System.out.println("scale = " + scale);
//真的解析图片
options.inJustDecodeBounds = false;
options.inSampleSize = scale;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.f1, options);
imageView.setImageBitmap(bitmap);

附(计算inSampleSize的工具方法):

   public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int heightRatio = Math.round((float) height
/ (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
inSampleSize = heightRatio < widthRatio ? widthRatio : heightRatio;
}
return inSampleSize;
}

Android 显示大图片的更多相关文章

  1. android高仿微信UI点击头像显示大图片效果

    用过微信的朋友朋友都见过微信中点击对方头像显示会加载大图,先贴两张图片说明下: 这种UI效果对用户的体验不错,今天突然有了灵感,试着去实现,结果就出来了.. 下面说说我的思路: 1.点击图片时跳转到另 ...

  2. Android显示GIF图片

    今天我们研究一下怎样在Android手机上显示GIF动态图片 首先须要在src文件夹下新建一个自己定义的View.代码例如以下: </pre><pre name="code ...

  3. Xamarin.Android 入门之:Bind java的jar文件+Android显示gif图片

    一.引言 在xamarin开发的时候,有时我们想要做一个功能,但是这个功能已经有人用java写好了,并且打包成了jar文件.那么我们可以直接把对方的jar文件拿过来用而不是重新用c#写代码. 关于bi ...

  4. android高仿微信UI点击头像显示大图片效果, Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    http://www.cnblogs.com/Jaylong/archive/2012/09/27/androidUI.html http://blog.csdn.net/xiaanming/arti ...

  5. android 显示gif图片

    在android中不支持gif格式的图片,但是由于我希望在我的程序中刚刚加载的时候有一个小人在跑步表示正在加载.而这个小人跑就是一个gif图片.也就是希望程序一启动时就加载gif图片.在网上查找了一些 ...

  6. jQuery点缩略图显示大图片

    2015年繁忙的一月份,无更多时间去学习ASP.NET MVC程序,二月份又是中国的新年,长达半个月的假期,望回到老家中,在无电脑无网络的日子里,能有更多时间陪伴年迈的父母亲. 今天学习jQuery的 ...

  7. android对大图片的缓存处理

    废话不多说,直接上代码 package com.huge.emj.common.util; import java.io.File; import java.io.FileInputStream; i ...

  8. Mono for Android 显示远程图片

    Main.axml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  9. 一天JavaScript示例-点击图片显示大图片添加鼠标

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

随机推荐

  1. oracle trunc 函数处理日期格式

    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;  --显示当前时间 2011-12-29 16:24:34 select trun ...

  2. bootstrap 分页样式代码

    bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...

  3. AutoPoco的使用

    官方开发指导https://autopoco.codeplex.com/documentation 初步使用: SimpleUser是自己要批量创建的类 1)创建管理工厂 IGenerationSes ...

  4. 【leetcode】8. String to Integer (atoi)

    题目描述: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ...

  5. HDU1857题解(逆向思维trie)

    题目link:http://acm.hdu.edu.cn/showproblem.php?pid=1857 先简述一下题目: 有一个RXC的字母矩形,R,C在500内,要匹配m个单词,m在100000 ...

  6. Linux 下cronolog分割catalina.out文件

    开发项目的时候查看日志,发现catalina.out已经有1个多G,日积月累的慢慢变大,幸亏及时发现还没有导致错误, tomcat默认日志之一输出在catalina.out文件中的,不会分割,不便于使 ...

  7. php下删除一篇文章生成的多个静态页面

    php自定义函数之删除一篇文章生成的多个静态页面,可能有多页的文章,都是需要考虑到的. 复制代码代码如下: //– 删除一篇文章生成的多个静态页面  //– 生成的文章名为 5.html 5_2.ht ...

  8. 纯CSS实现多选组件

    mark: http://blog.meathill.com/tech/fe/create-multiple-select-component-with-pure-css.html Demo: 小宝3 ...

  9. 在Linux中,如何取出一个字符串的前5位

    问: 在Linux中,如何取出一个字符串的前5位? 常用的一些方法如下: [tough@toughhou ~]$ str=abcdef [tough@toughhou ~]$ echo $str ab ...

  10. sp_depends 查询在sybase中依赖的函数

    sp_depends 查询在sybase中依赖的函数. sp_depends tblEK7_policy_exclude sp_depends tblEK7_agent_exclude