English 中文(简体)
Android 3.x图像作物冻结(Motorola xoom 和 cer iconia)
原标题:Android 3.x image crop freezing(motorola xoom and acer iconia)
Intent intent = new Intent("com.android.camera.action.CROP");

File path = this.getExternalFilesDir("tmp");
File file = new File(path, "tmp_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
Uri tmpUri = Uri.fromFile(file);

intent.setData(selectedImage);
intent.putExtra(MediaStore.EXTRA_OUTPUT, tmpUri);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("crop", "true");
intent.putExtra("scale", "true");
intent.putExtra("outputX", 100);
intent.putExtra("outputY", 100);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);

intent.putExtra("return-data", false);        
startActivityForResult(intent, REQUEST_CROP);

I am using this code to crop image. It works perfectly on android 2.x. But on 3.1(motorola xoom) and 3.2(acer iconia) the application freeze after I select crop area and tap "Save" (onActivityResult is not even called). There is a real Uri to real image in selectedImage variable, so the problem is not here.

On the 3.1 and 3.2 android emulators the application works perfectly too. Does anyone know what s the problem?

问题回答

问题可能是已经开始的作物活动。 “选择” = “真实”外在装置上工作并不保证,因为它是非正式的。

See this thread for more details:

对这种方法,它为我工作。 它不是地雷,我是在 st流中建立的:。 如何种植比特马中心,如图像调查?

public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();

    // Compute the scaling factors to fit the new height and width, respectively.
    // To cover the final image, the final scaling will be the bigger 
    // of these two.
    float xScale = (float) newWidth / sourceWidth;
    float yScale = (float) newHeight / sourceHeight;
    float scale = Math.max(xScale, yScale);

    // Now get the size of the source bitmap when scaled
    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    // Let s find out the upper left coordinates if the scaled bitmap
    // should be centered in the new size give by the parameters
    float left = (newWidth - scaledWidth) / 2;
    float top = (newHeight - scaledHeight) / 2;

    // The target rectangle for the new, scaled version of the source bitmap will now
    // be
    RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    // Finally, we create a new bitmap of the specified size and draw our new,
    // scaled bitmap onto it.
    Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
    Canvas canvas = new Canvas(dest);
    canvas.drawBitmap(source, null, targetRect, null);

    return dest;
}

替换<代码>intent.setData(s selectedImage); by intent.setDataAndType(s selectedImage, “image/*”;





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签