Bitmap之getDensity和setDensity函数
package com.loaderman.customviewdemo; import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cat); ImageView iv1 = (ImageView) findViewById(R.id.img1);
iv1.setImageBitmap(bitmap);
int density = bitmap.getDensity();
Log.d("loaderman", "density:" + density + " width:" + bitmap.getWidth() + " height:" + bitmap.getHeight()); int scaledDensity = density * 2;
bitmap.setDensity(scaledDensity);
Log.d("loaderman", "density:" + bitmap.getDensity() + " width:" + bitmap.getWidth() + " height:" + bitmap.getHeight());
ImageView iv2 = (ImageView) findViewById(R.id.img2);
iv2.setImageBitmap(bitmap); } }
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter" />
<ImageView
android:id="@+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter" /> </LinearLayout>
</ScrollView>
效果:

Bitmap之getDensity和setDensity函数的更多相关文章
- bitMap算法实现以及ckHash函数类,将字符串映射成数字,同时可以将数字映射成字符串
ckHash函数类,将字符串映射成数字,同时可以将数字映射成字符串 说明 1.所谓的BitMap就是用一个bit位来标记某个元素所对应的value,而key即是该元素,由于BitMap使用了bit位来 ...
- Bitmap之getPixel和setPixel函数
package com.loaderman.customviewdemo; import android.app.Activity; import android.graphics.Bitmap; i ...
- MD中bitmap源代码分析--设置流程
1. 同步/异步刷磁盘 Bitmap文件写磁盘分同步和异步两种: 1) 同步置位:当盘阵有写请求时,对应的bitmap文件相应bit被置位,bitmap内存页被设置了DIRTY标志.而在下发写请求给磁 ...
- Android O Bitmap 内存分配
我们知道,一般认为在Android进程的内存模型中,heap分为两部分,一部分是native heap,一部分是Dalvik heap(实际上也是native heap的一部分). Andro ...
- 十二、Android UI开发专题(转)
http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=18736&page=1#pid89255Android UI开发专题(一) 之界面设计 近期很 ...
- Android UI开发专题(转)
http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=18736&page=1#pid89255 Android UI开发专题(一) 之界面设计 近期 ...
- 不一样视角的Glide剖析
推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) Glide是一个快速高效的Android图片加载库,注重于平滑的 ...
- canvas.drawBitmap()频繁调用导致应用崩溃问题
因为opengl不熟,要在opengl上面贴文字 时间紧所以用到一个折中的办法 文字转bitmap 因为文字较多,对话形式 还要分行,分段,逻辑处理的比较复杂 运行中会有闪退发生,且不可 ...
- Android 适配知识点
转载:https://gold.xitu.io/post/58451c1d8e450a006c0f1c74 支持多种屏幕 Android 可在各种具有不同屏幕尺寸和密度的设备上运行.对于 应用,And ...
随机推荐
- nginx实现fastcgi反向代理
实现FastCGI: CGI的由来:最早的Web服务器只能简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html文件,但是后期随着网站功能增多网站开发也越 ...
- Linux命令——chkconfig
拓展:如何增加一个系统服务service chkconfig本身用法不复杂,其作用是控制service是否开机启动. 对于CentOS而言,7.X版本已经不再使用SysV,SysV相关的命令基本上没有 ...
- SUSE Ceph Cephfs - Storage6
(1)Policy 配置文件,添加MDS角色定义 # vim /srv/pillar/ceph/proposals/policy.cfg # MDS role-mds/cluster/mds*.sls ...
- IAR建立stm32工程
stm32是一个当下非常流行的微控制器,很多人都加入了学习stm32的行列中,常用的stm32编译器有IAR和mdk两种,接下来是利用stm32固件库3.5在IAR下的建立的工程模板历程: 1.在常用 ...
- dict sorted by value. 字典根据 值排序
d = [('a', 24), ('g', 52), ('i', 12)] print(sorted(d),key = lambda x:x[1]) sorted (字典,排序的依据: 字典[key] ...
- mybatis3.1-[topic-16-17]-映射文件_增删改查_insert_获取自增主键的值
笔记要点出错分析与总结 /**测试第16章的增,删,改 的内容 * 错误1: <insert id="addEmp" parameterType="com.bean ...
- 《The One!》团队作业4:基于原型的团队项目需求调研与分析
项目 内容 作业所属课程 所属课程 作业要求 作业要求 团队名称 < The One !> 作业学习目标 (1)体验以原型设计为基础的团队软件项目需求获取技巧与方法.(2)学习利用UML模 ...
- 云计算(6)--一些MapReduce的例子
例1:文件的字符串查找 这里reduce不做merge的工作,因为每行都是不一样的,不能merge. 与传统的grep程序相比,使用MapReduce可以加快处理,因为1它是Distributed的, ...
- 【Mac】打开配置文件,添加/修改环境变量
打开文件编辑器: 进入终端,输入open -e .bash_profile或者open -t ~/.bash_profile 打开profile文件 填写配置的环境变量: #示例代码 export ...
- Vue之nextTick()
我们有时候操作 DOM,是想在 data 数据变更的时候进行操作. 那么,我们应该怎么做呢? index.html <!DOCTYPE html> <html lang=" ...