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 ...
随机推荐
- Python_字符串相关操作
1.字符串切片操作: str1='hello word' startIndex=0 #开始索引位置 endIndex=5 #结束索引位置+1 step=2 #步长 print(str1[startIn ...
- jade注释
在jade里面注释是有多种方式的 单行注释,加两个//,跟js里面一样 //h1.title#title imoock jade study => <!--h1.title#title i ...
- python函数式编程-匿名函数
>>> map(lambda x: x * x, [, , , , , , , , ]) [, , , , , , , , ] 关键字lambda表示匿名函数,冒号前面的x表示函数参 ...
- SHELL编程基础01
首先shell是在linux下运行的一种环境,它是以shell脚本来运行的,学会了它基本可以解决任何问题,也可以用shell脚本开发. 和java,python的相比,其弱类型的语言没有那么复杂的结构 ...
- Geohash 基本知识及 .NET 下计算相邻8个区域编码
目录 一.简介 二.计算方法 三.GeoHash的精度 四.查找相邻8个区域的Geohash编码(.NET) 五.MySQL 中使用 GeoHash 最近项目中需要搜索周边的 POI 信息,查找的过程 ...
- js插件讲解_javascript原生日历插件讲解
效果图如下: html代码 <div class="date-control" id="date-control"> <span id=&qu ...
- Selenium常用API的使用java语言之13-多表单切换
在 Web 应用中经常会遇到 frame/iframe 表单嵌套页面的应用, WebDriver 只能在一个页面上对元素识别与 定位, 对于 frame/iframe 表单内嵌页面上的元素无法直接定位 ...
- IDEA去掉屏幕中间的白色竖线
现状: 打开File->Settings->Editor->General->Appearance,去掉勾选: 修改后:
- hive优化,开启压缩功能
1.开启hive作业mapreduce任务中间压缩功能: 对于数据进行压缩可以减少job中map和reduce task间的数据传输量.对于中间数据压缩,选择一个低cpu开销编/解码器要不选择一个压缩 ...
- JQ实现点击两个按钮切换内容
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...