Search in sources :

Example 1 with Matrix

use of android.graphics.Matrix in project TakePhoto by crazycodeboy.

the class ImageRotateUtil method rotateBitmapByDegree.

/**
     * 将图片按照某个角度进行旋转
     *
     * @param bm     需要旋转的图片
     * @param degree 旋转角度
     * @return 旋转后的图片
     */
private Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
    Bitmap returnBm = null;
    // 根据旋转角度,生成旋转矩阵
    Matrix matrix = new Matrix();
    matrix.postRotate(degree);
    try {
        // 将原始图片按照旋转矩阵进行旋转,并得到新的图片
        returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    } catch (OutOfMemoryError e) {
    }
    if (returnBm == null) {
        returnBm = bm;
    }
    if (bm != returnBm) {
        bm.recycle();
    }
    return returnBm;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix)

Example 2 with Matrix

use of android.graphics.Matrix in project cw-omnibus by commonsguy.

the class AnimatorProxy method computeRect.

private void computeRect(final RectF r, View view) {
    // compute current rectangle according to matrix transformation
    final float w = view.getWidth();
    final float h = view.getHeight();
    // use a rectangle at 0,0 to make sure we don't run into issues with scaling
    r.set(0, 0, w, h);
    final Matrix m = mTempMatrix;
    m.reset();
    transformMatrix(m, view);
    mTempMatrix.mapRect(r);
    r.offset(view.getLeft(), view.getTop());
    // Straighten coords if rotations flipped them
    if (r.right < r.left) {
        final float f = r.right;
        r.right = r.left;
        r.left = f;
    }
    if (r.bottom < r.top) {
        final float f = r.top;
        r.top = r.bottom;
        r.bottom = f;
    }
}
Also used : Matrix(android.graphics.Matrix)

Example 3 with Matrix

use of android.graphics.Matrix in project AndroidTraining by mixi-inc.

the class AnimatorProxy method computeRect.

private void computeRect(final RectF r, View view) {
    // compute current rectangle according to matrix transformation
    final float w = view.getWidth();
    final float h = view.getHeight();
    // use a rectangle at 0,0 to make sure we don't run into issues with scaling
    r.set(0, 0, w, h);
    final Matrix m = mTempMatrix;
    m.reset();
    transformMatrix(m, view);
    mTempMatrix.mapRect(r);
    r.offset(view.getLeft(), view.getTop());
    // Straighten coords if rotations flipped them
    if (r.right < r.left) {
        final float f = r.right;
        r.right = r.left;
        r.left = f;
    }
    if (r.bottom < r.top) {
        final float f = r.top;
        r.top = r.bottom;
        r.bottom = f;
    }
}
Also used : Matrix(android.graphics.Matrix)

Example 4 with Matrix

use of android.graphics.Matrix in project rainbow by juankysoriano.

the class CaptureSketchUtils method storeThumbnail.

/**
     * A copy of the Android internals StoreThumbnail method, it used with the insertImage to
     * populate the android.provider.MediaStore.Images.Media#insertImage with all the correct
     * meta data. The StoreThumbnail method is private so it must be duplicated here.
     *
     * @see android.provider.MediaStore.Images.Media (StoreThumbnail private method)
     */
private static Bitmap storeThumbnail(ContentResolver cr, Bitmap source, long id, float width, float height, int kind) {
    // create the matrix to scale it
    Matrix matrix = new Matrix();
    float scaleX = width / source.getWidth();
    float scaleY = height / source.getHeight();
    matrix.setScale(scaleX, scaleY);
    Bitmap thumb = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    ContentValues values = new ContentValues(4);
    values.put(Images.Thumbnails.KIND, kind);
    values.put(Images.Thumbnails.IMAGE_ID, (int) id);
    values.put(Images.Thumbnails.HEIGHT, thumb.getHeight());
    values.put(Images.Thumbnails.WIDTH, thumb.getWidth());
    Uri url = cr.insert(Images.Thumbnails.EXTERNAL_CONTENT_URI, values);
    try {
        OutputStream thumbOut = cr.openOutputStream(url);
        thumb.compress(Bitmap.CompressFormat.JPEG, 100, thumbOut);
        thumbOut.close();
        return thumb;
    } catch (FileNotFoundException ex) {
        return null;
    } catch (IOException ex) {
        return null;
    }
}
Also used : ContentValues(android.content.ContentValues) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Uri(android.net.Uri)

Example 5 with Matrix

use of android.graphics.Matrix in project qksms by moezbhatti.

the class ComposeView method rotateImage.

public static Bitmap rotateImage(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
Also used : Matrix(android.graphics.Matrix)

Aggregations

Matrix (android.graphics.Matrix)1590 Bitmap (android.graphics.Bitmap)487 Paint (android.graphics.Paint)344 RectF (android.graphics.RectF)276 Test (org.junit.Test)154 Canvas (android.graphics.Canvas)139 Rect (android.graphics.Rect)127 ColorMatrix (android.graphics.ColorMatrix)87 Point (android.graphics.Point)79 View (android.view.View)78 Path (android.graphics.Path)74 ImageView (android.widget.ImageView)73 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)67 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)67 IOException (java.io.IOException)61 Drawable (android.graphics.drawable.Drawable)48 BitmapFactory (android.graphics.BitmapFactory)47 Bundle (android.os.Bundle)46 ViewGroup (android.view.ViewGroup)44 PointF (android.graphics.PointF)42