zoukankan      html  css  js  c++  java
  • 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 + "  " + bitmap.getWidth() + " height:" + bitmap.getHeight());
    
            int scaledDensity = density * 2;
            bitmap.setDensity(scaledDensity);
            Log.d("loaderman", "density:" + bitmap.getDensity() + "  " + 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>

    效果:

  • 相关阅读:
    设计模式读书笔记-----适配器模式
    设计模式读书笔记-----命令模式
    一种另类的解决URL中文乱码问题--对中文进行加密、解密处理
    设计模式读书笔记-----单例模式
    Mysql的一些小知识点
    2-逻辑题二
    1-逻辑题一
    12-1054. 求平均值
    11-1048.数字加密
    10-string类的length()返回值一起的问题
  • 原文地址:https://www.cnblogs.com/loaderman/p/10231687.html
Copyright © 2011-2022 走看看