Search in sources :

Example 91 with Matrix

use of android.graphics.Matrix in project android-pathview by geftimov.

the class SvgUtils method getPathsForViewport.

/**
     * Render the svg to canvas and catch all the paths while rendering.
     *
     * @param width  - the width to scale down the view to,
     * @param height - the height to scale down the view to,
     * @return All the paths from the svg.
     */
public List<SvgPath> getPathsForViewport(final int width, final int height) {
    final float strokeWidth = mSourcePaint.getStrokeWidth();
    Canvas canvas = new Canvas() {

        private final Matrix mMatrix = new Matrix();

        @Override
        public int getWidth() {
            return width;
        }

        @Override
        public int getHeight() {
            return height;
        }

        @Override
        public void drawPath(Path path, Paint paint) {
            Path dst = new Path();
            //noinspection deprecation
            getMatrix(mMatrix);
            path.transform(mMatrix, dst);
            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(strokeWidth);
            mPaths.add(new SvgPath(dst, paint));
        }
    };
    rescaleCanvas(width, height, strokeWidth, canvas);
    return mPaths;
}
Also used : Path(android.graphics.Path) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 92 with Matrix

use of android.graphics.Matrix in project XobotOS by xamarin.

the class OrientedBoundingBox method toPath.

/**
     * Currently used for debugging purpose only.
     *
     * @hide
     */
public Path toPath() {
    Path path = new Path();
    float[] point = new float[2];
    point[0] = -width / 2;
    point[1] = height / 2;
    Matrix matrix = new Matrix();
    matrix.setRotate(orientation);
    matrix.postTranslate(centerX, centerY);
    matrix.mapPoints(point);
    path.moveTo(point[0], point[1]);
    point[0] = -width / 2;
    point[1] = -height / 2;
    matrix.mapPoints(point);
    path.lineTo(point[0], point[1]);
    point[0] = width / 2;
    point[1] = -height / 2;
    matrix.mapPoints(point);
    path.lineTo(point[0], point[1]);
    point[0] = width / 2;
    point[1] = height / 2;
    matrix.mapPoints(point);
    path.lineTo(point[0], point[1]);
    path.close();
    return path;
}
Also used : Path(android.graphics.Path) Matrix(android.graphics.Matrix)

Example 93 with Matrix

use of android.graphics.Matrix in project XobotOS by xamarin.

the class Transformation method clear.

/**
     * Reset the transformation to a state that leaves the object
     * being animated in an unmodified state. The transformation type is
     * {@link #TYPE_BOTH} by default.
     */
public void clear() {
    if (mMatrix == null) {
        mMatrix = new Matrix();
    } else {
        mMatrix.reset();
    }
    mAlpha = 1.0f;
    mTransformationType = TYPE_BOTH;
}
Also used : Matrix(android.graphics.Matrix)

Example 94 with Matrix

use of android.graphics.Matrix in project ZI by yixia.

the class BitmapUtils method rotate.

// Rotates the bitmap by the specified degree.
// If a new bitmap is created, the original bitmap is recycled.
public static Bitmap rotate(Bitmap b, int degrees) {
    if (degrees != 0 && b != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try {
            Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
            if (b != b2) {
                b.recycle();
                b = b2;
            }
        } catch (OutOfMemoryError ex) {
        // We have no memory to rotate. Return the original bitmap.
        }
    }
    return b;
}
Also used : Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix)

Example 95 with Matrix

use of android.graphics.Matrix in project ZI by yixia.

the class CropImage method onSaveClicked.

private void onSaveClicked() {
    // bitmap doesn't have to be read into memory
    if (mSaving)
        return;
    if (mCrop == null) {
        return;
    }
    mSaving = true;
    Rect r = mCrop.getCropRect();
    int width = r.width();
    int height = r.height();
    // If we are circle cropping, we want alpha channel, which is the
    // third param here.
    Bitmap croppedImage = Bitmap.createBitmap(width, height, mCircleCrop ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    {
        Canvas canvas = new Canvas(croppedImage);
        Rect dstRect = new Rect(0, 0, width, height);
        canvas.drawBitmap(mBitmap, r, dstRect, null);
    }
    if (mCircleCrop) {
        // OK, so what's all this about?
        // Bitmaps are inherently rectangular but we want to return
        // something that's basically a circle.  So we fill in the
        // area around the circle with alpha.  Note the all important
        // PortDuff.Mode.CLEAR.
        Canvas c = new Canvas(croppedImage);
        Path p = new Path();
        p.addCircle(width / 2F, height / 2F, width / 2F, Path.Direction.CW);
        c.clipPath(p, Region.Op.DIFFERENCE);
        c.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
    }
    /* If the output is required to a specific size then scale or fill */
    if (mOutputX != 0 && mOutputY != 0) {
        if (mScale) {
            /* Scale the image to the required dimensions */
            Bitmap old = croppedImage;
            croppedImage = BitmapUtils.transform(new Matrix(), croppedImage, mOutputX, mOutputY, mScaleUp);
            if (old != croppedImage) {
                old.recycle();
            }
        } else {
            /* Don't scale the image crop it to the size requested.
				 * Create an new image with the cropped image in the center and
				 * the extra space filled.
				 */
            // Don't scale the image but instead fill it so it's the
            // required dimension
            Bitmap b = Bitmap.createBitmap(mOutputX, mOutputY, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(b);
            Rect srcRect = mCrop.getCropRect();
            Rect dstRect = new Rect(0, 0, mOutputX, mOutputY);
            int dx = (srcRect.width() - dstRect.width()) / 2;
            int dy = (srcRect.height() - dstRect.height()) / 2;
            /* If the srcRect is too big, use the center part of it. */
            srcRect.inset(Math.max(0, dx), Math.max(0, dy));
            /* If the dstRect is too big, use the center part of it. */
            dstRect.inset(Math.max(0, -dx), Math.max(0, -dy));
            /* Draw the cropped bitmap in the center */
            canvas.drawBitmap(mBitmap, srcRect, dstRect, null);
            /* Set the cropped bitmap as the new bitmap */
            croppedImage.recycle();
            croppedImage = b;
        }
    }
    // Return the cropped image directly or save it to the specified URI.
    Bundle myExtras = getIntent().getExtras();
    if (myExtras != null && (myExtras.getParcelable("data") != null || myExtras.getBoolean("return-data"))) {
        Bundle extras = new Bundle();
        extras.putParcelable("data", croppedImage);
        setResult(RESULT_OK, (new Intent()).setAction("inline-data").putExtras(extras));
        finish();
    } else if (myExtras != null && myExtras.getBoolean("set-wallpaper")) {
        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getString(R.string.cropimage_wallpaper_is_setting));
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        new AsyncTask<Bitmap, Void, Boolean>() {

            protected void onPreExecute() {
                dialog.show();
            }

            protected void onPostExecute(Boolean result) {
                reset();
                if (result)
                    showToast(R.string.cropimage_wallpaper_success);
                else
                    showToast(R.string.cropimage_wallpaper_failed);
                CropImage.this.finish();
            }

            protected void onCancelled() {
                reset();
            }

            @Override
            protected Boolean doInBackground(Bitmap... image) {
                WallpaperManager myWallpaperManager = WallpaperManager.getInstance(CropImage.this);
                if (image != null && image[0] != null) {
                    try {
                        myWallpaperManager.setBitmap(image[0]);
                    } catch (IOException e) {
                        return false;
                    }
                } else {
                    return false;
                }
                return true;
            }

            private void reset() {
                dialog.dismiss();
            }

            private void showToast(int resID) {
                Toast.makeText(CropImage.this, getString(resID), Toast.LENGTH_SHORT).show();
            }
        }.execute(croppedImage);
    } else {
        final Bitmap b = croppedImage;
        BitmapUtils.startBackgroundJob(this, null, getString(R.string.cropimage_image_saving), new Runnable() {

            public void run() {
                saveOutput(b);
            }
        }, mHandler);
    }
}
Also used : Path(android.graphics.Path) Rect(android.graphics.Rect) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) IOException(java.io.IOException) ProgressDialog(android.app.ProgressDialog) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) WallpaperManager(android.app.WallpaperManager)

Aggregations

Matrix (android.graphics.Matrix)970 Bitmap (android.graphics.Bitmap)254 Paint (android.graphics.Paint)201 RectF (android.graphics.RectF)155 Rect (android.graphics.Rect)99 Test (org.junit.Test)93 Canvas (android.graphics.Canvas)80 ImageView (android.widget.ImageView)67 View (android.view.View)65 Point (android.graphics.Point)52 Bundle (android.os.Bundle)45 GhostView (android.view.GhostView)40 ViewGroup (android.view.ViewGroup)39 ColorMatrix (android.graphics.ColorMatrix)38 Drawable (android.graphics.drawable.Drawable)38 IOException (java.io.IOException)38 BitmapHunter.forRequest (com.squareup.picasso.BitmapHunter.forRequest)36 TestUtils.makeBitmap (com.squareup.picasso.TestUtils.makeBitmap)36 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)36 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)36