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 ...
随机推荐
- 删除svn用户
以win7为例 1.进入c:/Users/[你的用户名]/AppData/Roaming/Subversion/auth目录,删除该目录下的所有文件: 2.重启eclipse/myeclipse,提交 ...
- 前端学习笔记--Visual Studio Code安装及中文显示
1.在官网https://code.visualstudio.com/下载对应的版本: 2.安装 一路点击下一步,选中 添加到PATH后,安装. 安装成功,可以直接打开使用: 把界面改成中文显示: ...
- c语言的函数指针
简单定义并间接调用 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<time.h> void singas ...
- 牛客练习赛33 E. tokitsukaze and Similar String (字符串哈希)
题目链接:https://ac.nowcoder.com/acm/contest/308/E 题意:中文题 见链接 题解:哈希预处理(三哈希模板) #include <bits/stdc++.h ...
- TDOA 基础之 双曲线
TDOA 的算法基础就是时间差,根据时间差换算出距离差,后面的数学理论知识就是双曲线交点问题. 双曲线方程是2次方程,解算曲线交点也就是两个2次方程求解. 首先看双曲线定义(百度百科): 双曲线(Hy ...
- splay 1296 营业额统计
有一个点超时,确实是个很简单的splay#include<cstdio> #include<iostream> using namespace std; int n,shu[1 ...
- 小象和老鼠 DP
小象和老鼠 DP \(N*M\)的网格图,格子\((i,j)\)有\(A_{i,j}\)个老鼠,问小象从左上角\((1,1)\)走到右下角\((N,M)\)看到的最少老鼠.小象可以看见老鼠,当且仅当老 ...
- (6)打鸡儿教你Vue.js
循环语句 循环使用 v-for 指令 <div id="app"> <ol> // 有序 <li v-for="item in items& ...
- puppteer的使用
官方文档:Puppeteer 今天大概介绍一下我项目用到的puppeteer操作: // 启动浏览器 const browser = await puppeteer.launch({ executab ...
- jsp 页面 javax.servlet.jsp.JspException cannot be resolved to a type 异常
<dependencies><dependency><groupId>javax.servlet</groupId><artifactId> ...