2

と から選択した画像をトリミングしようとしGalleryていCameraます。ほとんどの画像をトリミングできません。を呼び出していませんonActivityResult()。以下は私のコードです。OKそして、画像をトリミングした後にクリックするたびに、次のログ猫出力を取得しました。

コード:

private void doCrop() {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(
            intent, 0);

    int size = list.size();
    if (size == 0) {
        Toast.makeText(this, "Can not find image crop app",
                Toast.LENGTH_SHORT).show();

        return;
    } else {
        intent.setData(mImageCaptureUri);

        // intent.putExtra("outputX", 200);
        // intent.putExtra("outputY", 200);
        // intent.putExtra("aspectX", 1);
        // intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", myImg.getWidth());
        intent.putExtra("outputY", myImg.getHeight());
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);
        intent.putExtra("outputFormat",
                Bitmap.CompressFormat.PNG.toString());
        intent.putExtra("crop", "true");

        if (size == 1) {
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent(new ComponentName(res.activityInfo.packageName,
                    res.activityInfo.name));

            startActivityForResult(i, CROP_FROM);
        }
    }
}

LogCat:

08-13 15:59:29.220: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:29.290: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:30.140: D/dalvikvm(288): GC_EXPLICIT freed 8K, 8% free 6788K/7367K, paused 2ms+2ms
08-13 15:59:34.110: D/dalvikvm(7247): GC_FOR_ALLOC freed 4824K, 44% free 10227K/18055K, paused 26ms
08-13 15:59:34.110: I/dalvikvm-heap(7247): Grow heap (frag case) to 11.929MB for 1956256-byte allocation
08-13 15:59:34.140: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 33% free 12137K/18055K, paused 23ms
08-13 15:59:34.190: D/dalvikvm(7247): GC_CONCURRENT freed 1K, 25% free 13662K/18055K, paused 2ms+3ms
08-13 15:59:34.230: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:34.280: D/dalvikvm(7247): GC_FOR_ALLOC freed 2554K, 33% free 12132K/18055K, paused 30ms
08-13 15:59:34.310: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:34.340: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 27% free 13331K/18055K, paused 30ms
08-13 15:59:34.390: D/dalvikvm(7247): GC_FOR_ALLOC freed 2000K, 33% free 12132K/18055K, paused 30ms
08-13 15:59:34.420: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:34.450: D/dalvikvm(7247): GC_FOR_ALLOC freed <1K, 26% free 13430K/18055K, paused 33ms
08-13 15:59:34.500: D/skia(7247): WARNING: One-shot allocator has already allocated (alloc count = 1)
08-13 15:59:34.530: D/dalvikvm(7247): GC_FOR_ALLOC freed 2097K, 28% free 13152K/18055K, paused 30ms
08-13 15:59:34.550: E/JavaBinder(7247): !!! FAILED BINDER TRANSACTION !!!
08-13 15:59:34.560: W/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40988068
08-13 15:59:39.620: D/dalvikvm(224): GC_EXPLICIT freed <1K, 31% free 17001K/24391K, paused 3ms+3ms
4

1 に答える 1

1

ソースコード全体を試してみてください。

私は同じプロジェクトを使用しています。そのアクティビティのコードは次のとおりです。

コード:

 private void doCrop() {
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );

    int size = list.size();

    if (size == 0) {            
        Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();

        return;
    } else {
        intent.setData(mImageCaptureUri);

        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);

        if (size == 1) {
            Intent i        = new Intent(intent);
            ResolveInfo res = list.get(0);

            i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CROP_FROM_CAMERA);
        } else {
            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 ) {
                    startActivityForResult( cropOptions.get(item).appIntent, CROP_FROM_CAMERA);
                }
            });


            builder.setOnCancelListener( new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel( DialogInterface dialog ) {

                    if (mImageCaptureUri != null ) {
                        getContentResolver().delete(mImageCaptureUri, null, null );
                        mImageCaptureUri = null;
                    }
                }
            } );

            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}
于 2012-08-16T05:29:46.813 に答える