android 裁剪图片库图片
package com.kankanla.m0531a;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_IMAGE_SELECT = 1;
private static final int REQUEST_IMAGE_CAPTURE = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setCutimg();
}
protected void setCutimg() {
Intent intent = new Intent();
intent.setAction(intent.ACTION_OPEN_DOCUMENT);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_IMAGE_SELECT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_IMAGE_SELECT:
Intent intent = new Intent("com.android.camera.action.CROP");
Uri uri = data.getData();
intent.setData(uri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
break;
case REQUEST_IMAGE_CAPTURE:
Bitmap bit = data.getExtras().getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.bit);
imageView.setImageBitmap(bit);
break;
}
}
}
}