我有代码在那里从我的Android设备启动相机,我想添加活动的功能,以便能够按照用户的意愿裁剪图像。
public class MainActivity extends AppCompatActivity {
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private Uri fileUri;
static final int REQUEST_IMAGE_CAPTURE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating the onClick Listener for the Scan Button
Button scanButton = (Button) findViewById(R.id.ScanButton);
scanButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//Creating an Intent to take a picture and return control to the calling application.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Launching the intent.
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
});
}
}
答案 0 :(得分:0)
您将使用与拍摄照片相同的方式使用其他Intent
。
Intent crop = new Intent("com.android.camera.action.CROP");
crop.setDataAndType(URI_OF_PIC_FROM_LAST_INTENT, "image/*");
crop.putExtra("crop", "true");
...
startActivityForResult(crop, REQUEST_CROP);
将URI_OF_PIC_FROM_LAST_INTENT
和REQUEST_CROP
替换为您自己的值。
Here's an example with more detail.
您也可以通过意图指定宽高比等内容。