我試圖裁剪圖像,因爲我們正在做Facebook。我在我的應用程序中使用了這個鏈接:https://github.com/oginotihiro/cropview這對我來說工作正常。但在這裏,當我點擊一個按鈕時,它直接去畫廊和裁剪選定的圖像。而不是我想打開我的設備中的相機,然後單擊形象和我想剪裁。我該怎麼做呢?有人可以幫助我。從相機捕獲圖像,並在android中進行固定裁剪
我試過這個code.But我無法實現。
imageBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
reset();
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_PICK);
}
});
doneBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final ProgressDialog dialog = ProgressDialog.show(StudentDetails.this, null, "Please wait…", true, false);
cropView.setVisibility(View.GONE);
layout4.setVisibility(View.GONE);
resultIv.setVisibility(View.VISIBLE);
layout3.setVisibility(View.GONE);
layoutUpload.setVisibility(View.VISIBLE);
// editTextName.setVisibility(View.GONE);
buttonUpload.setVisibility(View.VISIBLE);
new Thread() {
public void run() {
croppedBitmap = cropView.getOutput();
runOnUiThread(new Runnable() {
@Override
public void run() {
// cropped image set
resultIv.setImageBitmap(croppedBitmap);
}
});
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
CropUtil.saveOutput(StudentDetails.this, destination, croppedBitmap, 1);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
});
}
}.start();
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_PICK) {
filePath = data.getData();
cropView.setVisibility(View.VISIBLE);
layoutImage.setVisibility(View.VISIBLE);
layout3.setVisibility(View.GONE);
layout4.setVisibility(View.VISIBLE);
textNameVal.setVisibility(View.GONE);
text1.setVisibility(View.GONE);
buttonUpload.setVisibility(View.GONE);
int x=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
int y=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
cropView.of(filePath).withAspect(x,y).initialize(StudentDetails.this);
}
}
對此有任何解決方案。由於我剛接觸android,因此無法做到這一點。 – Amshu