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 ...
随机推荐
- 博客迁到CSDN
之前一直是博客园和CSDN博客同步更新 现在不在博客园继续写博客,十一国庆节假后只用CSDN博客了.祝各位访客国庆节快乐! CSDN博客地址: http://blog.csdn.net/it_liuc ...
- jQuery实现列表自动滚动
需要在页面中一个小的区域循环滚动展示新闻(公告.活动.图片等等),并且,鼠标悬停时停止滚动并提示,离开后,继续滚动. 效果图: 上干货 html: <div id="news&q ...
- xamarin android——数据绑定到控件(四)
本文为通过自定义列表适配器定义ListView,以上文为基础,基于ListActivity. 定义列表项布局,包含一个图片显示,标题和描述 <LinearLayout xmlns:android ...
- DirectSound学习(三)--类、方法、属性翻译
DirectSound.Device :Contains methods and properties used to create buffer objects, manage devices, a ...
- 【Qt】Qt环境搭建(Visual Studio)【转】
简述 经常有人问我编写Qt程序时使用什么IDE,其实这个真的很难回答(各有所长),只能说看个人爱好了,因为我两个都用,而且两个都很喜欢(比较多情吧O(∩_∩)O~)! 下面将进行Qt Creator与 ...
- android SDK Manager更新不了,出现错误提示:"Failed to fetch URL..."!
可以用以下办法解决: 使用SDK Manager更新时出现问题 Failed to fetch URL https://dl-ssl.google.com/android/repository/rep ...
- C#获取“所有用户桌面”的路径
想用C#得到The All Users Desktop(Public\Desktop)的路径. 原来以为很简单,然而 Environment.GetFolderPath(Environment.Spe ...
- C++ 关联容器详解——从内部结构到应用
关联容器不同于顺序容器的是:顺序容器底层用数组实现,为线性结构:关联容器在实现中,用到的非线性存储方式: 顺序容器是通过元素在容器中的位置顺序存储和访问元素,而关联容器是通过键(key)存储和读取元素 ...
- 《WPF程序设计指南》读书笔记——第3章 内容的概念
1.Content属性及字体相关的属性 using System; using System.Windows; using System.Windows.Media; namespace LY.Dis ...
- CodeForces 18C
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...