private static Bitmap createThumbnail( Point size, Context context, Uri uri, byte[] imageBytes, Resources res, int resId, int rotation, boolean leftAligned) { int width = size.x; int height = size.y; BitmapCropTask cropTask; if (uri != null) { cropTask = new BitmapCropTask(context, uri, null, rotation, width, height, false, true, null); } else if (imageBytes != null) { cropTask = new BitmapCropTask(imageBytes, null, rotation, width, height, false, true, null); } else { cropTask = new BitmapCropTask(context, res, resId, null, rotation, width, height, false, true, null); } Point bounds = cropTask.getImageBounds(); if (bounds == null || bounds.x == 0 || bounds.y == 0) { return null; } Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(rotation); float[] rotatedBounds = new float[] {bounds.x, bounds.y}; rotateMatrix.mapPoints(rotatedBounds); rotatedBounds[0] = Math.abs(rotatedBounds[0]); rotatedBounds[1] = Math.abs(rotatedBounds[1]); RectF cropRect = WallpaperCropActivity.getMaxCropRect( (int) rotatedBounds[0], (int) rotatedBounds[1], width, height, leftAligned); cropTask.setCropBounds(cropRect); if (cropTask.cropBitmap()) { return cropTask.getCroppedBitmap(); } else { return null; } }
protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone) { int rotation = getRotationFromExif(this, uri); BitmapCropTask cropTask = new BitmapCropTask(this, uri, null, rotation, 0, 0, true, false, null); final Point bounds = cropTask.getImageBounds(); Runnable onEndCrop = new Runnable() { public void run() { updateWallpaperDimensions(bounds.x, bounds.y); if (finishActivityWhenDone) { setResult(Activity.RESULT_OK); finish(); } } }; cropTask.setOnEndRunnable(onEndCrop); cropTask.setNoCrop(true); cropTask.execute(); }