Search in sources :

Example 6 with Matrix

use of android.graphics.Matrix in project Signal-Android by WhisperSystems.

the class CanvasView method render.

public void render(Canvas canvas) {
    if (this.canvas == null)
        return;
    float scaleX = 1.0F * canvas.getWidth() / this.canvas.getWidth();
    float scaleY = 1.0F * canvas.getHeight() / this.canvas.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(scaleX, scaleY);
    for (int i = 0; i < this.historyPointer; i++) {
        Path path = this.pathLists.get(i);
        Paint paint = this.paintLists.get(i);
        Path scaledPath = new Path();
        path.transform(matrix, scaledPath);
        Paint scaledPaint = new Paint(paint);
        scaledPaint.setStrokeWidth(scaledPaint.getStrokeWidth() * scaleX);
        canvas.drawPath(scaledPath, scaledPaint);
    }
}
Also used : Path(android.graphics.Path) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 7 with Matrix

use of android.graphics.Matrix in project actor-platform by actorapp.

the class ImageHelper method fixExif.

private static Bitmap fixExif(Bitmap src, int exifOrientation) {
    try {
        final Matrix bitmapMatrix = new Matrix();
        switch(exifOrientation) {
            case 1:
                // top left
                break;
            case 2:
                bitmapMatrix.postScale(-1, 1);
                // top right
                break;
            case 3:
                bitmapMatrix.postRotate(180);
                // bottom right
                break;
            case 4:
                bitmapMatrix.postRotate(180);
                bitmapMatrix.postScale(-1, 1);
                // bottom left
                break;
            case 5:
                bitmapMatrix.postRotate(90);
                bitmapMatrix.postScale(-1, 1);
                // left top
                break;
            case 6:
                bitmapMatrix.postRotate(90);
                // right top
                break;
            case 7:
                bitmapMatrix.postRotate(270);
                bitmapMatrix.postScale(-1, 1);
                // right bottom
                break;
            case 8:
                bitmapMatrix.postRotate(270);
                // left bottom
                break;
            default:
                // Unknown
                break;
        }
        // Create new bitmap.
        return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), bitmapMatrix, false);
    } catch (Exception e) {
    // TODO: handle exception
    }
    return null;
}
Also used : Matrix(android.graphics.Matrix) IOException(java.io.IOException)

Example 8 with Matrix

use of android.graphics.Matrix in project TouchImageView by MikeOrtiz.

the class TouchImageView method sharedConstructing.

private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (mScaleType == null) {
        mScaleType = ScaleType.FIT_CENTER;
    }
    minScale = 1;
    maxScale = 3;
    superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setState(State.NONE);
    onDrawReady = false;
    super.setOnTouchListener(new PrivateOnTouchListener());
}
Also used : Matrix(android.graphics.Matrix) GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 9 with Matrix

use of android.graphics.Matrix in project Carbon by ZieIony.

the class CheckableDrawable method renderSVGs.

private void renderSVGs() {
    Rect bounds = getBounds();
    if (bounds.width() <= 0 && bounds.height() <= 0)
        return;
    try {
        {
            SVG svg = SVG.getFromResource(context, checkedRes);
            checkedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(checkedBitmap);
            svg.setDocumentWidth(checkedBitmap.getWidth());
            svg.setDocumentHeight(checkedBitmap.getHeight());
            svg.renderToCanvas(canvas);
            checkedShader = new BitmapShader(checkedBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            Matrix matrix = new Matrix();
            matrix.postTranslate(bounds.left, bounds.top);
            checkedShader.setLocalMatrix(matrix);
        }
        {
            SVG svg2 = SVG.getFromResource(context, uncheckedRes);
            uncheckedBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(uncheckedBitmap);
            svg2.setDocumentWidth(uncheckedBitmap.getWidth());
            svg2.setDocumentHeight(uncheckedBitmap.getHeight());
            svg2.renderToCanvas(canvas);
        }
        {
            SVG svg3 = SVG.getFromResource(context, filledRes);
            filledBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(filledBitmap);
            svg3.setDocumentWidth(filledBitmap.getWidth());
            svg3.setDocumentHeight(filledBitmap.getHeight());
            svg3.renderToCanvas(canvas);
        }
        maskBitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ARGB_8888);
        maskCanvas = new Canvas(maskBitmap);
        radius = (float) (Math.sqrt(2) * bounds.width() / 2);
    } catch (SVGParseException e) {
        Log.e(CheckableDrawable.class.getSimpleName(), "There was an error parsing SVG");
    } catch (NullPointerException e) {
    // TODO: what is this catch for?
    }
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) SVG(com.caverock.androidsvg.SVG) SVGParseException(com.caverock.androidsvg.SVGParseException) Canvas(android.graphics.Canvas) BitmapShader(android.graphics.BitmapShader)

Example 10 with Matrix

use of android.graphics.Matrix in project WoWoViewPager by Nightonke.

the class WoWoPathView method getResizedBitmap.

private Bitmap getResizedBitmap(Bitmap bm, float newWidth, float newHeight) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = 1, scaleHeight = 1;
    if (newWidth != -1) {
        scaleWidth = newWidth / width;
        if (newHeight != -1) {
            scaleHeight = newHeight / height;
        } else {
            scaleHeight = scaleWidth;
        }
    } else {
        if (newHeight != -1) {
            scaleWidth = scaleHeight = newHeight / height;
        }
    }
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    bm.recycle();
    return resizedBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint)

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