Search in sources :

Example 16 with Matrix

use of android.graphics.Matrix in project android_frameworks_base by ParanoidAndroid.

the class ThumbnailUtils method extractThumbnail.

/**
     * Creates a centered bitmap of the desired size.
     *
     * @param source original bitmap source
     * @param width targeted width
     * @param height targeted height
     * @param options options used during thumbnail extraction
     */
public static Bitmap extractThumbnail(Bitmap source, int width, int height, int options) {
    if (source == null) {
        return null;
    }
    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap thumbnail = transform(matrix, source, width, height, OPTIONS_SCALE_UP | options);
    return thumbnail;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix)

Example 17 with Matrix

use of android.graphics.Matrix in project android_frameworks_base by ParanoidAndroid.

the class RecentsPanelView method updateThumbnail.

private void updateThumbnail(ViewHolder h, Bitmap thumbnail, boolean show, boolean anim) {
    if (thumbnail != null) {
        // Should remove the default image in the frame
        // that this now covers, to improve scrolling speed.
        // That can't be done until the anim is complete though.
        thumbnail.setDensity(mAndroidDpi);
        h.thumbnailViewImage.setImageBitmap(thumbnail);
        // we haven't set a bitmap before, or if the bitmap size has changed
        if (h.thumbnailViewImageBitmap == null || h.thumbnailViewImageBitmap.getWidth() != thumbnail.getWidth() || h.thumbnailViewImageBitmap.getHeight() != thumbnail.getHeight()) {
            if (mFitThumbnailToXY) {
                h.thumbnailViewImage.setScaleType(ScaleType.FIT_XY);
            } else {
                Matrix scaleMatrix = new Matrix();
                float scale = mThumbnailWidth / (float) thumbnail.getWidth();
                scaleMatrix.setScale(scale, scale);
                h.thumbnailViewImage.setScaleType(ScaleType.MATRIX);
                h.thumbnailViewImage.setImageMatrix(scaleMatrix);
            }
        }
        if (show && h.thumbnailView.getVisibility() != View.VISIBLE) {
            if (anim) {
                h.thumbnailView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.recent_appear));
            }
            h.thumbnailView.setVisibility(View.VISIBLE);
        }
        h.thumbnailViewImageBitmap = thumbnail;
    }
}
Also used : Matrix(android.graphics.Matrix)

Example 18 with Matrix

use of android.graphics.Matrix in project android_frameworks_base by ParanoidAndroid.

the class RecentsScrollViewPerformanceHelper method drawCallback.

public void drawCallback(Canvas canvas, int left, int right, int top, int bottom, int scrollX, int scrollY, float topFadingEdgeStrength, float bottomFadingEdgeStrength, float leftFadingEdgeStrength, float rightFadingEdgeStrength, int mPaddingTop) {
    if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
        if (mFadePaint == null) {
            mFadePaint = new Paint();
            mFadeMatrix = new Matrix();
            // use use a height of 1, and then wack the matrix each time we
            // actually use it.
            mFade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
            // PULL OUT THIS CONSTANT
            mFadePaint.setShader(mFade);
        }
        // draw the fade effect
        boolean drawTop = false;
        boolean drawBottom = false;
        boolean drawLeft = false;
        boolean drawRight = false;
        float topFadeStrength = 0.0f;
        float bottomFadeStrength = 0.0f;
        float leftFadeStrength = 0.0f;
        float rightFadeStrength = 0.0f;
        final float fadeHeight = mFadingEdgeLength;
        int length = (int) fadeHeight;
        // overlapping fades produce odd-looking artifacts
        if (mIsVertical && (top + length > bottom - length)) {
            length = (bottom - top) / 2;
        }
        // also clip horizontal fades if necessary
        if (!mIsVertical && (left + length > right - length)) {
            length = (right - left) / 2;
        }
        if (mIsVertical) {
            topFadeStrength = Math.max(0.0f, Math.min(1.0f, topFadingEdgeStrength));
            drawTop = topFadeStrength * fadeHeight > 1.0f;
            bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, bottomFadingEdgeStrength));
            drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
        }
        if (!mIsVertical) {
            leftFadeStrength = Math.max(0.0f, Math.min(1.0f, leftFadingEdgeStrength));
            drawLeft = leftFadeStrength * fadeHeight > 1.0f;
            rightFadeStrength = Math.max(0.0f, Math.min(1.0f, rightFadingEdgeStrength));
            drawRight = rightFadeStrength * fadeHeight > 1.0f;
        }
        if (drawTop) {
            mFadeMatrix.setScale(1, fadeHeight * topFadeStrength);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, right, top + length, mFadePaint);
            if (mBlackPaint == null) {
                // Draw under the status bar at the top
                mBlackPaint = new Paint();
                mBlackPaint.setColor(0xFF000000);
            }
            canvas.drawRect(left, top - mPaddingTop, right, top, mBlackPaint);
        }
        if (drawBottom) {
            mFadeMatrix.setScale(1, fadeHeight * bottomFadeStrength);
            mFadeMatrix.postRotate(180);
            mFadeMatrix.postTranslate(left, bottom);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, bottom - length, right, bottom, mFadePaint);
        }
        if (drawLeft) {
            mFadeMatrix.setScale(1, fadeHeight * leftFadeStrength);
            mFadeMatrix.postRotate(-90);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, left + length, bottom, mFadePaint);
        }
        if (drawRight) {
            mFadeMatrix.setScale(1, fadeHeight * rightFadeStrength);
            mFadeMatrix.postRotate(90);
            mFadeMatrix.postTranslate(right, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(right - length, top, right, bottom, mFadePaint);
        }
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 19 with Matrix

use of android.graphics.Matrix in project android-app-common-tasks by multidots.

the class HighlightView method setup.

public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio) {
    if (circle) {
        maintainAspectRatio = true;
    }
    mMatrix = new Matrix(m);
    mCropRect = cropRect;
    mImageRect = new RectF(imageRect);
    mMaintainAspectRatio = maintainAspectRatio;
    mCircle = circle;
    mInitialAspectRatio = mCropRect.width() / mCropRect.height();
    mDrawRect = computeLayout();
    mFocusPaint.setARGB(125, 50, 50, 50);
    mNoFocusPaint.setARGB(125, 50, 50, 50);
    mOutlinePaint.setStrokeWidth(3F);
    mOutlinePaint.setStyle(Paint.Style.STROKE);
    mOutlinePaint.setAntiAlias(true);
    mMode = ModifyMode.None;
    init();
}
Also used : RectF(android.graphics.RectF) Matrix(android.graphics.Matrix)

Example 20 with Matrix

use of android.graphics.Matrix in project android-app-common-tasks by multidots.

the class Util method rotateImage.

// Thong added for rotate
public static Bitmap rotateImage(Bitmap src, float degree) {
    // create new matrix
    Matrix matrix = new Matrix();
    // setup rotation degree
    matrix.postRotate(degree);
    return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.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