Bitmap scaling (a)

First with the option Bitmap bitmap compression of the half, then the matrix scaling 0.3f

public class MainActivity extends AppCompatActivity {
    WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView imageView = findViewById(R.id.image);
        BitmapFactory.Options newOpts = new BitmapFactory.Options();
        newOpts.inJustDecodeBounds = false;
        newOpts.inSampleSize = 2;//设置缩放比例
        //Re-read pictures, pay attention to this time has been set back to false options.inJustDecodeBounds the 
        Bitmap Bitmap = BitmapFactory.decodeResource (getResources (), R.drawable.icon8, newOpts); 

        int width = bitmap.getWidth ();
         int height = Bitmap .getHeight ();
         // obtain matrix parameters you want to zoom 
        the matrix matrix = new new the matrix (); 
        matrix.postScale ( 0.3f , 0.3f );
         // get new pictures 
        Bitmap newBitMap = Bitmap.createBitmap (Bitmap, 0 , 0 , width, height, 
                Matrix, to true );

        imageView.setImageBitmap(newBitMap);


    }

}

 

Guess you like

Origin www.cnblogs.com/Ocean123123/p/10965894.html