• BitmapFactory.Options对图片进行缩放


    package com.pingyijinren.helloworld.activity;
    
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Matrix;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.ImageView;
    import com.pingyijinren.helloworld.R;
    
    public class MainActivity extends AppCompatActivity {
        private ImageView imageView;
        private Bitmap bitmap;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            imageView=(ImageView)findViewById(R.id.imageView);
            bitmap=zoomBitmap(2,2);
            imageView.setImageBitmap(bitmap);
        }
    
        private Bitmap zoomBitmap(int width,int height) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            options.inPurgeable=true;
            options.inInputShareable=true;
            bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.beauty, options);
            float scaleWidth = (float) 1.0 / width;
            float scaleHeight = (float) 1.0 / height;
            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);
            Bitmap scaleBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            bitmap.recycle();
            return scaleBitmap;
        }
    }
  • 相关阅读:
    Jmeter在命令行运行技巧
    Tomcat6 一些调优设置内存和连接数
    用例结构优化心得
    LoadRunner 调用dll方法
    DLL接口自动化测试总结
    Loadrunner进行md5加密方法
    Loadrunner检查点使用总结
    网络上可供测试的Web Service
    04 json,xml混合封装通信
    03 xml封装通信接口
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5553970.html
Copyright © 2020-2023  润新知