Java Code Examples for android.graphics.Matrix#setRotate()
The following examples show how to use
android.graphics.Matrix#setRotate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapUtils.java From giffun with Apache License 2.0 | 6 votes |
/** * Rotate the given bitmap by the given degrees.<br> * New bitmap is created and the old one is recycled. */ private static Bitmap rotateAndFlipBitmapInt( Bitmap bitmap, int degrees, boolean flipHorizontally, boolean flipVertically) { if (degrees > 0 || flipHorizontally || flipVertically) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); matrix.postScale(flipHorizontally ? -1 : 1, flipVertically ? -1 : 1); Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); if (newBitmap != bitmap) { bitmap.recycle(); } return newBitmap; } else { return bitmap; } }
Example 2
Source File: BitmapUtils.java From Android-Image-Cropper with Apache License 2.0 | 6 votes |
/** * Rotate the given bitmap by the given degrees.<br> * New bitmap is created and the old one is recycled. */ private static Bitmap rotateAndFlipBitmapInt( Bitmap bitmap, int degrees, boolean flipHorizontally, boolean flipVertically) { if (degrees > 0 || flipHorizontally || flipVertically) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); matrix.postScale(flipHorizontally ? -1 : 1, flipVertically ? -1 : 1); Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false); if (newBitmap != bitmap) { bitmap.recycle(); } return newBitmap; } else { return bitmap; } }
Example 3
Source File: CameraLauncher.java From reader with MIT License | 6 votes |
/** * Figure out if the bitmap should be rotated. For instance if the picture was taken in * portrait mode * * @param rotate * @param bitmap * @return rotated bitmap */ private Bitmap getRotatedBitmap(int rotate, Bitmap bitmap, ExifHelper exif) { Matrix matrix = new Matrix(); if (rotate == 180) { matrix.setRotate(rotate); } else { matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); } try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); exif.resetOrientation(); } catch (OutOfMemoryError oom) { // You can run out of memory if the image is very large: // http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html // If this happens, simply do not rotate the image and return it unmodified. // If you do not catch the OutOfMemoryError, the Android app crashes. } return bitmap; }
Example 4
Source File: CropImageView.java From ImagePicker with Apache License 2.0 | 6 votes |
/** * @param bitmap 要旋转的图片 * @param degrees 选择的角度(单位 度) * @return 旋转后的Bitmap */ public Bitmap rotate(Bitmap bitmap, int degrees) { if (degrees != 0 && bitmap != null) { Matrix matrix = new Matrix(); matrix.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try { Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); if (bitmap != rotateBitmap) { // bitmap.recycle(); return rotateBitmap; } } catch (OutOfMemoryError ex) { ex.printStackTrace(); } } return bitmap; }
Example 5
Source File: BIGChart.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
protected void updateRainbow() { animationAngle = (animationAngle + 1) % 360; //Animation matrix: int[] rainbow = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE , Color.CYAN}; Shader shader = new LinearGradient(0, 0, 0, 20, rainbow, null, Shader.TileMode.MIRROR); Matrix matrix = new Matrix(); matrix.setRotate(animationAngle); shader.setLocalMatrix(matrix); mSgv.getPaint().setShader(shader); invalidate(); }
Example 6
Source File: WallpaperPickerActivity.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
@Thunk 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 = Utils.getMaxCropRect( (int) rotatedBounds[0], (int) rotatedBounds[1], width, height, leftAligned); cropTask.setCropBounds(cropRect); if (cropTask.cropBitmap()) { return cropTask.getCroppedBitmap(); } else { return null; } }
Example 7
Source File: Watermark.java From AndroidWM with Apache License 2.0 | 5 votes |
/** * Adjust the rotation of a bitmap. * * @param bitmap input bitmap. * @param orientationAngle the orientation angle. * @return {@link Bitmap} the new bitmap. */ private Bitmap adjustPhotoRotation(Bitmap bitmap, final int orientationAngle) { Matrix matrix = new Matrix(); matrix.setRotate(orientationAngle, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); }
Example 8
Source File: PXTransformParser.java From pixate-freestyle-android with Apache License 2.0 | 5 votes |
private Matrix parseRotate() { float angle = angleValue(); Matrix result = new Matrix(); if (isInTypeSet(LENGTH_SET)) { float x = lengthValue(); float y = lengthValue(); result.setTranslate(x, y); result.setRotate(angle); result.setTranslate(-x, -y); } else { result.setRotate(angle); } return result; }
Example 9
Source File: NOChart.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
protected void updateRainbow() { animationAngle = (animationAngle + 1) % 360; //Animation matrix: int[] rainbow = {Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE , Color.CYAN}; Shader shader = new LinearGradient(0, 0, 0, 20, rainbow, null, Shader.TileMode.MIRROR); Matrix matrix = new Matrix(); matrix.setRotate(animationAngle); shader.setLocalMatrix(matrix); mSgv.getPaint().setShader(shader); invalidate(); }
Example 10
Source File: CropDrawingUtils.java From imageCrop with MIT License | 5 votes |
public static boolean setImageToScreenMatrix(Matrix dst, RectF image, RectF screen, int rotation) { RectF rotatedImage = new RectF(); dst.setRotate(rotation, image.centerX(), image.centerY()); if (!dst.mapRect(rotatedImage, image)) { return false; // fails for rotations that are not multiples of 90 // degrees } boolean rToR = dst.setRectToRect(rotatedImage, screen, Matrix.ScaleToFit.CENTER); boolean rot = dst.preRotate(rotation, image.centerX(), image.centerY()); return rToR && rot; }
Example 11
Source File: MrzRecognizer.java From Telegram with GNU General Public License v2.0 | 5 votes |
public static Result recognize(byte[] yuvData, int width, int height, int rotation) { Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); setYuvBitmapPixels(bmp, yuvData); Matrix m = new Matrix(); m.setRotate(rotation); int minSize = Math.min(width, height); int dh = Math.round(minSize * 0.704f); boolean swap = rotation == 90 || rotation == 270; bmp = Bitmap.createBitmap(bmp, swap ? (width / 2 - dh / 2) : 0, swap ? 0 : (height / 2 - dh / 2), swap ? dh : minSize, swap ? minSize : dh, m, false); return recognize(bmp, false); }
Example 12
Source File: CircleLoadingView.java From ImageLoader with Apache License 2.0 | 5 votes |
private void initRect(float width, float height) { if (width > height) { rect.left = (width - height) / 2; rect.right = width - rect.left; rect.top = 0; rect.bottom = height; } else { rect.left = 0; rect.right = width; rect.top = (height - width) / 2; rect.bottom = height - rect.top; } int circleThickness = (int) (width*circleThicknessRatio); paint.setStrokeWidth(circleThickness); rect.left = rect.left + circleThickness / 2; rect.right = rect.right - circleThickness / 2; rect.top = rect.top + circleThickness / 2; rect.bottom = rect.bottom - circleThickness / 2; //因为这个圆环是顺时针旋转的,所有endColor, startColor在shader上反过来写了 shader = new SweepGradient(width / 2, height / 2, endColor, startColor); matrix = new Matrix(); matrix.setRotate(-90 + 20,width/2,height/2);//着色器初始位置,12点钟方法加20度,收尾留一点空隙 shader.setLocalMatrix(matrix); paint.setShader(shader); }
Example 13
Source File: IndicatorLayout.java From android-project-wo2b with Apache License 2.0 | 4 votes |
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) { super(context); mArrowImageView = new ImageView(context); Drawable arrowD = getResources().getDrawable(R.drawable.ptr_indicator_arrow); mArrowImageView.setImageDrawable(arrowD); final int padding = getResources().getDimensionPixelSize(R.dimen.ptr_indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView); int inAnimResId, outAnimResId; switch (mode) { case PULL_FROM_END: inAnimResId = R.anim.pull_to_refresh_slide_in_from_bottom; outAnimResId = R.anim.pull_to_refresh_slide_out_to_bottom; setBackgroundResource(R.drawable.ptr_indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId = R.anim.pull_to_refresh_slide_in_from_top; outAnimResId = R.anim.pull_to_refresh_slide_out_to_top; setBackgroundResource(R.drawable.ptr_indicator_bg_top); break; } mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator = new LinearInterpolator(); mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); }
Example 14
Source File: WallpaperCropActivity.java From TurboLauncher with Apache License 2.0 | 4 votes |
protected void cropImageAndSetWallpaper(Uri uri, OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) { boolean centerCrop = getResources().getBoolean(R.bool.center_crop); // Get the crop boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; Display d = getWindowManager().getDefaultDisplay(); Point displaySize = new Point(); d.getSize(displaySize); boolean isPortrait = displaySize.x < displaySize.y; Point defaultWallpaperSize = getDefaultWallpaperSize(getResources(), getWindowManager()); // Get the crop RectF cropRect = mCropView.getCrop(); int cropRotation = mCropView.getImageRotation(); float cropScale = mCropView.getWidth() / (float) cropRect.width(); Point inSize = mCropView.getSourceDimensions(); Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(cropRotation); float[] rotatedInSize = new float[] { inSize.x, inSize.y }; rotateMatrix.mapPoints(rotatedInSize); rotatedInSize[0] = Math.abs(rotatedInSize[0]); rotatedInSize[1] = Math.abs(rotatedInSize[1]); // ADJUST CROP WIDTH // Extend the crop all the way to the right, for parallax // (or all the way to the left, in RTL) float extraSpace; if (centerCrop) { extraSpace = 2f * Math.min(rotatedInSize[0] - cropRect.right, cropRect.left); } else { extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left; } // Cap the amount of extra width float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width(); extraSpace = Math.min(extraSpace, maxExtraSpace); if (centerCrop) { cropRect.left -= extraSpace / 2f; cropRect.right += extraSpace / 2f; } else { if (ltr) { cropRect.right += extraSpace; } else { cropRect.left -= extraSpace; } } // ADJUST CROP HEIGHT if (isPortrait) { cropRect.bottom = cropRect.top + defaultWallpaperSize.y / cropScale; } else { // LANDSCAPE float extraPortraitHeight = defaultWallpaperSize.y / cropScale - cropRect.height(); float expandHeight = Math.min(Math.min(rotatedInSize[1] - cropRect.bottom, cropRect.top), extraPortraitHeight / 2); cropRect.top -= expandHeight; cropRect.bottom += expandHeight; } final int outWidth = (int) Math.round(cropRect.width() * cropScale); final int outHeight = (int) Math.round(cropRect.height() * cropScale); Runnable onEndCrop = new Runnable() { public void run() { updateWallpaperDimensions(outWidth, outHeight); if (finishActivityWhenDone) { setResult(Activity.RESULT_OK); finish(); } } }; BitmapCropTask cropTask = new BitmapCropTask(this, uri, cropRect, cropRotation, outWidth, outHeight, true, false, onEndCrop); if (onBitmapCroppedHandler != null) { cropTask.setOnBitmapCropped(onBitmapCroppedHandler); } cropTask.execute(); }
Example 15
Source File: IndicatorLayout.java From MagicHeaderViewPager with Apache License 2.0 | 4 votes |
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) { super(context); mArrowImageView=new ImageView(context); // Drawable arrowD=getResources().getDrawable(R.drawable.indicator_arrow); Drawable arrowD=new ColorDrawable(Color.TRANSPARENT); mArrowImageView.setImageDrawable(arrowD); final int padding=getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView); int inAnimResId, outAnimResId; switch(mode) { case PULL_FROM_END: inAnimResId=R.anim.slide_in_from_bottom; outAnimResId=R.anim.slide_out_to_bottom; setBackgroundResource(R.drawable.indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix=new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId=R.anim.slide_in_from_top; outAnimResId=R.anim.slide_out_to_top; setBackgroundResource(R.drawable.indicator_bg_top); break; } mInAnim=AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim=AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator=new LinearInterpolator(); mRotateAnimation=new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation=new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); }
Example 16
Source File: FilmstripItemUtils.java From Camera2 with Apache License 2.0 | 4 votes |
/** * Load the thumbnail of an image from an {@link java.io.InputStream}. * * @param stream The input stream of the image. * @param imageWidth Image width. * @param imageHeight Image height. * @param widthBound The bound of the width of the decoded image. * @param heightBound The bound of the height of the decoded image. * @param orientation The orientation of the image. The image will be rotated * clockwise in degrees. * @param maximumPixels The bound for the number of pixels of the decoded image. * @return {@code null} if the decoding failed. */ public static Bitmap loadImageThumbnailFromStream(InputStream stream, int imageWidth, int imageHeight, int widthBound, int heightBound, int orientation, int maximumPixels) { /** 32K buffer. */ byte[] decodeBuffer = new byte[32 * 1024]; if (orientation % 180 != 0) { int dummy = imageHeight; imageHeight = imageWidth; imageWidth = dummy; } // Generate Bitmap of maximum size that fits into widthBound x heightBound. // Algorithm: start with full size and step down in powers of 2. int targetWidth = imageWidth; int targetHeight = imageHeight; int sampleSize = 1; while (targetHeight > heightBound || targetWidth > widthBound || targetHeight > GL11.GL_MAX_TEXTURE_SIZE || targetWidth > GL11.GL_MAX_TEXTURE_SIZE || targetHeight * targetWidth > maximumPixels) { sampleSize <<= 1; targetWidth = imageWidth / sampleSize; targetHeight = imageWidth / sampleSize; } // For large (> MAXIMUM_TEXTURE_SIZE) high aspect ratio (panorama) // Bitmap requests: // Step 1: ask for double size. // Step 2: scale maximum edge down to MAXIMUM_TEXTURE_SIZE. // // Here's the step 1: double size. if ((heightBound > GL11.GL_MAX_TEXTURE_SIZE || widthBound > GL11.GL_MAX_TEXTURE_SIZE) && targetWidth * targetHeight < maximumPixels / 4 && sampleSize > 1) { sampleSize >>= 2; } BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = sampleSize; opts.inTempStorage = decodeBuffer; Bitmap b = BitmapFactory.decodeStream(stream, null, opts); if (b == null) { return null; } // Step 2: scale maximum edge down to maximum texture size. // If Bitmap maximum edge > MAXIMUM_TEXTURE_SIZE, which can happen for panoramas, // scale to fit in MAXIMUM_TEXTURE_SIZE. if (b.getWidth() > GL11.GL_MAX_TEXTURE_SIZE || b.getHeight() > GL11.GL_MAX_TEXTURE_SIZE) { int maxEdge = Math.max(b.getWidth(), b.getHeight()); b = Bitmap.createScaledBitmap(b, b.getWidth() * GL11.GL_MAX_TEXTURE_SIZE / maxEdge, b.getHeight() * GL11.GL_MAX_TEXTURE_SIZE / maxEdge, false); } // Not called often because most modes save image data non-rotated. if (orientation != 0 && b != null) { Matrix m = new Matrix(); m.setRotate(orientation); b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, false); } return b; }
Example 17
Source File: IndicatorLayout.java From Favorite-Android-Client with Apache License 2.0 | 4 votes |
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) { super(context); mArrowImageView = new ImageView(context); Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow); mArrowImageView.setImageDrawable(arrowD); final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView); int inAnimResId, outAnimResId; switch (mode) { case PULL_FROM_END: inAnimResId = R.anim.slide_in_from_bottom; outAnimResId = R.anim.slide_out_to_bottom; setBackgroundResource(R.drawable.indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId = R.anim.slide_in_from_top; outAnimResId = R.anim.slide_out_to_top; setBackgroundResource(R.drawable.indicator_bg_top); break; } mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator = new LinearInterpolator(); mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); }
Example 18
Source File: BoundedRect.java From imageCrop with MIT License | 4 votes |
private Matrix getInverseRotMatrix() { Matrix m = new Matrix(); m.setRotate(-rot, outer.centerX(), outer.centerY()); return m; }
Example 19
Source File: IndicatorLayout.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) { super(context); mArrowImageView = new ImageView(context); Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow); mArrowImageView.setImageDrawable(arrowD); final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding); mArrowImageView.setPadding(padding, padding, padding, padding); addView(mArrowImageView); int inAnimResId, outAnimResId; switch (mode) { case PULL_FROM_END: inAnimResId = R.anim.slide_in_from_bottom; outAnimResId = R.anim.slide_out_to_bottom; setBackgroundResource(R.drawable.indicator_bg_bottom); // Rotate Arrow so it's pointing the correct way mArrowImageView.setScaleType(ScaleType.MATRIX); Matrix matrix = new Matrix(); matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f); mArrowImageView.setImageMatrix(matrix); break; default: case PULL_FROM_START: inAnimResId = R.anim.slide_in_from_top; outAnimResId = R.anim.slide_out_to_top; setBackgroundResource(R.drawable.indicator_bg_top); break; } mInAnim = AnimationUtils.loadAnimation(context, inAnimResId); mInAnim.setAnimationListener(this); mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId); mOutAnim.setAnimationListener(this); final Interpolator interpolator = new LinearInterpolator(); mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateAnimation.setInterpolator(interpolator); mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mRotateAnimation.setFillAfter(true); mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mResetRotateAnimation.setInterpolator(interpolator); mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION); mResetRotateAnimation.setFillAfter(true); }
Example 20
Source File: BitmapUtils.java From Android-Next with Apache License 2.0 | 2 votes |
/** * 旋转图片 * * @param bmp 原始图片 * @param angle 旋转的角度 * @return */ public static Bitmap rotate(Bitmap bmp, float angle) { Matrix matrixRotateLeft = new Matrix(); matrixRotateLeft.setRotate(angle); return Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrixRotateLeft, true); }