갤러리에서 이미지를 선택하고 imageview
에 표시하는 시나리오가있는 안드로이드 앱을 만들고 있습니다. 자르기 시점에 이미지를 확대하고 싶습니다. 이미지를 확대/축소하는 데 TouchImageView
클래스를 사용하고 있습니다.이미지 확대/축소 및 이미지보기에 자른 이미지 표시
TouchImageView
을 ImageView
에만 적용하려면 잘 작동합니다. 그러나 작물 기능과 함께 사용하면 효과가 없습니다.
ImageView
에 한 번에 자르기 + 확대/축소 기능을 적용해야합니까? 모든 유형의 도움을 주시면 감사하겠습니다. 아래는 내 시도입니다.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println(requestCode);
if (resultCode != RESULT_OK) {
return;
}
Bitmap bitmap;
switch (requestCode) {
case 0:
mImageCaptureUri = data.getData();
doCrop();
break;
case 1:
mImageCaptureUri = data.getData();
doCrop();
break;
case 2:
Bundle extras = data.getExtras();
/**
* After cropping the image, get the bitmap of the cropped image and
* display it on imageview.
*/
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
img_v.setImageBitmap(photo);
//myBitmap = getCircleImage(photo);
//String image_base64 = postimage();
// new PostCoverTask().execute(userid, image_base64);
}
File f = new File(mImageCaptureUri.getPath());
/**
* Delete the temporary image
*/
if (f.exists())
f.delete();
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private void doCrop()
{
final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();
/**
* Open image crop app by starting an intent
* ‘com.android.camera.action.CROP‘.
*/
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(mImageCaptureUri,"image/*");
/**
* Check if there is image cropper app installed.
*/
List<ResolveInfo> list = getPackageManager().queryIntentActivities(
intent, 0);
int size = list.size();
/**
* If there is no image cropper app, display warning message
*/
if (size == 0)
{
Toast.makeText(this, "Can not find image crop app",
Toast.LENGTH_SHORT).show();
return;
}
else
{
size=1;
/**
* Specify the image path, crop dimension and scale
*/
// intent.setData(mImageCaptureUri);
intent.putExtra("crop", "true");
intent.putExtra("outputX", 256);
intent.putExtra("outputY", 256);
intent.putExtra("aspectX",3);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("scaleUpIfNeeded", true);
intent.putExtra("return-data", true);
System.out.println("Put image in Extra");
/**
* There is posibility when more than one image cropper app exist,
* so we have to check for it first. If there is only one app, open
* then app.
*/
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res=null ;
for (int i1=0;i1<list.size();i1++)
{
if(list.get(i1)!=null)
{
res = list.get(i1);
break;
}
}
i.setComponent(new ComponentName(res.activityInfo.packageName,
res.activityInfo.name));
System.out.println("size is equal to "+size);
startActivityForResult(i, 2);
}
else
{
System.out.println("size is equal to "+size);
/**
* If there are several app exist, create a custom chooser to
* let user selects the app.
*/
for (ResolveInfo res : list)
{
final CropOption co = new CropOption();
co.title = getPackageManager().getApplicationLabel(
res.activityInfo.applicationInfo);
co.icon = getPackageManager().getApplicationIcon(
res.activityInfo.applicationInfo);
co.appIntent = new Intent(intent);
co.appIntent
.setComponent(new ComponentName(
res.activityInfo.packageName,
res.activityInfo.name));
cropOptions.add(co);
}
CropOptionAdapter adapter = new CropOptionAdapter(
getApplicationContext(), cropOptions);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose Crop App");
builder.setAdapter(adapter,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item) {
System.out.println("option "+cropOptions.get(item));
//startActivityForResult(cropOptions.get(item).appIntent,
// CROP_FROM_CAMERA);
System.out.println("builder.setAdapter");
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
if (mImageCaptureUri != null) {
getContentResolver().delete(mImageCaptureUri, null,
null);
mImageCaptureUri = null;
}
System.out.println("Click on cancel");
}
});
AlertDialog alert = builder.create();
alert.show();
System.out.println("alert");
}
}
}
당신이 할 수있다, 당신은 "어쩌려 구't 작업"에 의해 무엇을 의미합니까 오류 메시지를 지정할 수 있을까요? –
아니 위 코드가 정확한지 확인하십시오. 그러나 그것은 단지 나를 위해 이미지를 자릅니다. 나는 자르기 동안 나는 줌인 후 이미지의 특정 부분을 자르거나 자른다. – user3710617