Android 显示大图片
主要的代码如下:
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 显示大图片的更多相关文章
- android高仿微信UI点击头像显示大图片效果
用过微信的朋友朋友都见过微信中点击对方头像显示会加载大图,先贴两张图片说明下: 这种UI效果对用户的体验不错,今天突然有了灵感,试着去实现,结果就出来了.. 下面说说我的思路: 1.点击图片时跳转到另 ...
- Android显示GIF图片
今天我们研究一下怎样在Android手机上显示GIF动态图片 首先须要在src文件夹下新建一个自己定义的View.代码例如以下: </pre><pre name="code ...
- Xamarin.Android 入门之:Bind java的jar文件+Android显示gif图片
一.引言 在xamarin开发的时候,有时我们想要做一个功能,但是这个功能已经有人用java写好了,并且打包成了jar文件.那么我们可以直接把对方的jar文件拿过来用而不是重新用c#写代码. 关于bi ...
- android高仿微信UI点击头像显示大图片效果, Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果
http://www.cnblogs.com/Jaylong/archive/2012/09/27/androidUI.html http://blog.csdn.net/xiaanming/arti ...
- android 显示gif图片
在android中不支持gif格式的图片,但是由于我希望在我的程序中刚刚加载的时候有一个小人在跑步表示正在加载.而这个小人跑就是一个gif图片.也就是希望程序一启动时就加载gif图片.在网上查找了一些 ...
- jQuery点缩略图显示大图片
2015年繁忙的一月份,无更多时间去学习ASP.NET MVC程序,二月份又是中国的新年,长达半个月的假期,望回到老家中,在无电脑无网络的日子里,能有更多时间陪伴年迈的父母亲. 今天学习jQuery的 ...
- android对大图片的缓存处理
废话不多说,直接上代码 package com.huge.emj.common.util; import java.io.File; import java.io.FileInputStream; i ...
- Mono for Android 显示远程图片
Main.axml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- 一天JavaScript示例-点击图片显示大图片添加鼠标
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- des算法的C#实现
DES是Data Encryption Standard(数据加密标准)的缩写.它是一种通过56位密钥来加密64位数据的方法. public class EncryptUtility{ #reg ...
- VxWorks 6.9 内核编程指导之读书笔记 -- VxWorks Small-Footprint Configuration
什么是Small-footprint? Small-footprint常见关键配置? 如何配置Small-footprint? 什么是Small-footprint? Small-footprint配 ...
- lex&yacc5--YYSTYPE
yacc里的YYSTYPE默认是int型的,当然也可以勇%union来定义联合但是由于程序需要,我要将YYSTYPE定义为我自己定义的一个struct的指针然后作为一个全局变量,让lex在扫描的时候, ...
- spring heibernate 调用存储过程
一:参考网址 http://sunbin123.iteye.com/blog/1007556 二:示例 @Autowired @Qualifier("jdbcTemplate") ...
- 解决xtraFinder在EI下不能使用问题
在EI (10.11)下,由于SIP(System Integrity Protection)机制,导致一些第三方插件不能使用,如xtrafinder. 要想使用,在目前的情况下,启用的方法:一种是安 ...
- HTML5如何重塑O2O用户体验
低频次垂直O2O服务应该继续开发原生APP吗?大家有没有发现做一个APP的推广成本和获取用户的成本越来越高?第二,用户安装APP之后,用户并不是经常点击使用APP的,那这是为什么?数据表明90%的O2 ...
- PHP7 新特性 简介
整理了一些常用的新特性,欢迎点赞!!! 新增操作符 1.?? $username = $_GET['user'] ?? ''; $username = isset($_GET['user']) ? $ ...
- 【转】FTP自动上传文件的perl脚本以及配置文件
这个perl文件将执行的任务是, 按照指定的文件夹目录,自动将该文件夹下的所有文件上传到指定ftp站点的指定目录下 本应用程序设计的几个基本理念是:工具箱再利用:尽可能利用已有的工具:简化运行步骤:不 ...
- N皇后问题2
Description Examine the checkerboard below and note that the six checkers are arranged on the board ...
- 使用Entity Framework时要注意的一些性能问题
http://diaosbook.com/Post/2012/12/9/performance-issue-in-select-one-or-few-colums-via-entityframewor ...