1、打开图库拿到图片
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.io.FileNotFoundException;
public class MainActivity extends AppCompatActivity {
int REQUEST_IMAGE_OPEN = 2;
ImageView imgView = null; //用于显示图片
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);//打开相册按钮
imgView = (ImageView) findViewById(R.id.imgView);
button.setOnClickListener(new View.OnClickListener() {