码迷,mamicode.com
首页 > 其他好文 > 详细

BitmapFactory.Options对图片进行缩放

时间:2016-06-02 19:42:24      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

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对图片进行缩放

标签:

原文地址:http://www.cnblogs.com/zqxLonely/p/5553970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!