BitmapFactory.Options对图片进行缩放
Posted zqxLonely
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; } }
以上是关于BitmapFactory.Options对图片进行缩放的主要内容,如果未能解决你的问题,请参考以下文章