Example usage for android.graphics RectF RectF

List of usage examples for android.graphics RectF RectF

Introduction

In this page you can find the example usage for android.graphics RectF RectF.

Prototype

public RectF(float left, float top, float right, float bottom) 

Source Link

Document

Create a new rectangle with the specified coordinates.

Usage

From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java

/**
 * Scale and center-crop a bitmap to fit the given dimensions.
 *///from w  ww .  j a  va 2 s  . com
public static Bitmap scaleAndCenterCropBitmap(Bitmap source, int newHeight, int newWidth) {
    if (source == null) {
        return null;
    }
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();

    float xScale = (float) newWidth / sourceWidth;
    float yScale = (float) newHeight / sourceHeight;
    float scale = Math.max(xScale, yScale);

    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    float left = (newWidth - scaledWidth) / 2;
    float top = (newHeight - scaledHeight) / 2;

    RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    Bitmap destination = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
    Canvas canvas = new Canvas(destination);
    canvas.drawBitmap(source, null, targetRect, null);

    return destination;
}

From source file:com.dynamixsoftware.printingsample.IntentApiFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.check_premium:
        new AlertDialog.Builder(requireContext()).setTitle(R.string.check_premium)
                .setMessage("" + intentApi.checkPremium()).setPositiveButton(R.string.ok, null).show();
        break;//w  w  w  .  jav  a2  s .  c  o  m
    case R.id.activate_online:
        final Context appContext = requireContext().getApplicationContext();
        intentApi.setLicense("YOUR_ACTIVATION_KEY", new ISetLicenseCallback.Stub() {
            @Override
            public void start() {
                toastInMainThread(appContext, "activate start");
            }

            @Override
            public void serverCheck() {
                toastInMainThread(appContext, "activate check server");
            }

            @Override
            public void finish(final Result arg0) {
                toastInMainThread(appContext, "activate finish " + (arg0 == Result.OK ? "ok" : "error"));
            }
        });
        break;
    case R.id.setup_printer:
        intentApi.setupCurrentPrinter();
        break;
    case R.id.change_options:
        intentApi.changePrinterOptions();
        break;
    case R.id.get_current_printer:
        try {
            IPrinterInfo printer = intentApi.getCurrentPrinter();
            Toast.makeText(requireContext().getApplicationContext(),
                    "current printer " + (printer != null ? printer.getName() : "null"), Toast.LENGTH_LONG)
                    .show();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.print_image:
        intentApi.print(Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)),
                "image/png", "from printing sample");
        break;
    case R.id.print_file:
        intentApi.print(Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC)),
                "application/msword", "from printing sample");
        break;
    case R.id.show_file_preview:
        intentApi.showFilePreview(
                Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC)),
                "application/msword", 0);
        break;
    case R.id.print_with_your_rendering:
        try {
            IDocument.Stub document = new IDocument.Stub() {

                private int thumbnailWidth;
                private int thumbnailHeight;

                @Override
                public Bitmap renderPageFragment(int arg0, Rect fragment) throws RemoteException {
                    IPrinterInfo printer = intentApi.getCurrentPrinter();
                    if (printer != null) {
                        Bitmap bitmap = Bitmap.createBitmap(fragment.width(), fragment.height(),
                                Bitmap.Config.ARGB_8888);
                        for (int i = 0; i < 3; i++)
                            try {
                                BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                                options.inDither = false;
                                if (i > 0) {
                                    options.inSampleSize = 1 << i;
                                }
                                Bitmap imageBMP = BitmapFactory.decodeStream(
                                        new FileInputStream(
                                                FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)),
                                        null, options);
                                Paint p = new Paint();
                                int imageWidth = 0;
                                int imageHeight = 0;
                                if (imageBMP != null) {
                                    imageWidth = imageBMP.getWidth();
                                    imageHeight = imageBMP.getHeight();
                                }
                                int xDpi = printer.getPrinterContext().getHResolution();
                                int yDpi = printer.getPrinterContext().getVResolution();
                                // in dots
                                int paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72;
                                int paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72;
                                float aspectH = (float) imageHeight / (float) paperHeight;
                                float aspectW = (float) imageWidth / (float) paperWidth;
                                aspectH = aspectH > 1 ? 1 / aspectH : aspectH;
                                aspectW = aspectW > 1 ? 1 / aspectW : aspectW;
                                RectF dst = new RectF(0, 0, fragment.width() * aspectW,
                                        fragment.height() * aspectH);
                                float sLeft = 0;
                                float sTop = fragment.top * aspectH;
                                float sRight = imageWidth;
                                float sBottom = fragment.top * aspectH + fragment.bottom * aspectH;
                                RectF source = new RectF(sLeft, sTop, sRight, sBottom);
                                Canvas canvas = new Canvas(bitmap);
                                canvas.drawColor(Color.WHITE);
                                // move image to actual printing area
                                dst.offsetTo(dst.left - fragment.left, dst.top - fragment.top);
                                Matrix matrix = new Matrix();
                                matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL);
                                canvas.drawBitmap(imageBMP, matrix, p);
                                break;
                            } catch (IOException ex) {
                                ex.printStackTrace();
                                break;
                            } catch (OutOfMemoryError ex) {
                                if (bitmap != null) {
                                    bitmap.recycle();
                                    bitmap = null;
                                }
                                continue;
                            }
                        return bitmap;
                    } else {
                        return null;
                    }
                }

                @Override
                public void initDeviceContext(IPrinterContext printerContext, int thumbnailWidth,
                        int thumbnailHeight) {
                    this.thumbnailWidth = thumbnailWidth;
                    this.thumbnailHeight = thumbnailHeight;
                }

                @Override
                public int getTotalPages() {
                    return 1;
                }

                @Override
                public String getDescription() {
                    return "PrintHand test page";
                }

                @Override
                public Bitmap getPageThumbnail(int arg0) throws RemoteException {
                    Bitmap bitmap = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight,
                            Bitmap.Config.ARGB_8888);
                    for (int i = 0; i < 3; i++)
                        try {
                            BitmapFactory.Options options = new BitmapFactory.Options();
                            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                            options.inDither = false;
                            if (i > 0) {
                                options.inSampleSize = 1 << i;
                            }
                            Bitmap imageBMP = BitmapFactory.decodeStream(
                                    new FileInputStream(
                                            FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)),
                                    null, options);
                            Paint p = new Paint();
                            int imageWidth = 0;
                            int imageHeight = 0;
                            if (imageBMP != null) {
                                imageWidth = imageBMP.getWidth();
                                imageHeight = imageBMP.getHeight();
                            }
                            // default
                            int paperWidth = 2481;
                            int paperHeight = 3507;
                            IPrinterInfo printer = intentApi.getCurrentPrinter();
                            if (printer != null) {
                                int xDpi = printer.getPrinterContext().getHResolution();
                                int yDpi = printer.getPrinterContext().getVResolution();
                                // in dots
                                paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72;
                                paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72;
                            }
                            float aspectW = (float) imageWidth / (float) paperWidth;
                            float aspectH = (float) imageHeight / (float) paperHeight;
                            RectF dst = new RectF(0, 0, thumbnailWidth * aspectW, thumbnailHeight * aspectH);
                            float sLeft = 0;
                            float sTop = 0;
                            float sRight = imageWidth;
                            float sBottom = imageHeight;
                            RectF source = new RectF(sLeft, sTop, sRight, sBottom);
                            Canvas canvas = new Canvas(bitmap);
                            canvas.drawColor(Color.WHITE);
                            Matrix matrix = new Matrix();
                            matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL);
                            canvas.drawBitmap(imageBMP, matrix, p);
                            break;
                        } catch (IOException ex) {
                            ex.printStackTrace();
                            break;
                        } catch (OutOfMemoryError ex) {
                            if (bitmap != null) {
                                bitmap.recycle();
                                bitmap = null;
                            }
                            continue;
                        }
                    return bitmap;
                }
            };
            intentApi.print(document);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.print_with_your_rendering_without_ui:
        try {
            IJob.Stub job = new IJob.Stub() {
                @Override
                public Bitmap renderPageFragment(int num, Rect fragment) throws RemoteException {
                    IPrinterInfo printer = intentApi.getCurrentPrinter();
                    if (printer != null) {
                        Bitmap bitmap = Bitmap.createBitmap(fragment.width(), fragment.height(),
                                Bitmap.Config.ARGB_8888);
                        for (int i = 0; i < 3; i++)
                            try {
                                BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                                options.inDither = false;
                                if (i > 0) {
                                    options.inSampleSize = 1 << i;
                                }
                                Bitmap imageBMP = BitmapFactory.decodeStream(
                                        new FileInputStream(
                                                FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)),
                                        null, options);
                                Paint p = new Paint();
                                int imageWidth = 0;
                                int imageHeight = 0;
                                if (imageBMP != null) {
                                    imageWidth = imageBMP.getWidth();
                                    imageHeight = imageBMP.getHeight();
                                }
                                int xDpi = printer.getPrinterContext().getHResolution();
                                int yDpi = printer.getPrinterContext().getVResolution();
                                // in dots
                                int paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72;
                                int paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72;
                                float aspectH = (float) imageHeight / (float) paperHeight;
                                float aspectW = (float) imageWidth / (float) paperWidth;
                                RectF dst = new RectF(0, 0, fragment.width() * aspectW,
                                        fragment.height() * aspectH);
                                float sLeft = 0;
                                float sTop = fragment.top * aspectH;
                                float sRight = imageWidth;
                                float sBottom = fragment.top * aspectH + fragment.bottom * aspectH;
                                RectF source = new RectF(sLeft, sTop, sRight, sBottom);
                                Canvas canvas = new Canvas(bitmap);
                                canvas.drawColor(Color.WHITE);
                                // move image to actual printing area
                                dst.offsetTo(dst.left - fragment.left, dst.top - fragment.top);
                                Matrix matrix = new Matrix();
                                matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL);
                                canvas.drawBitmap(imageBMP, matrix, p);
                                break;
                            } catch (IOException ex) {
                                ex.printStackTrace();
                                break;
                            } catch (OutOfMemoryError ex) {
                                if (bitmap != null) {
                                    bitmap.recycle();
                                    bitmap = null;
                                }
                                continue;
                            }
                        return bitmap;
                    } else {
                        return null;
                    }
                }

                @Override
                public int getTotalPages() {
                    return 1;
                }
            };
            intentApi.print(job, 1);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.print_image_with_print_hand_rendering_without_ui:
        try {
            intentApi.print("PrintingSample", "image/png",
                    Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.change_image_options:
        try {
            List<PrintHandOption> imageOptions = intentApi.getImagesOptions();
            changeRandomOption(imageOptions);
            intentApi.setImagesOptions(imageOptions);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.print_file_with_print_hand_rendering_without_ui:
        try {
            intentApi.print("PrintingSample", "application/ms-word",
                    Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC)));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.print_protected_file_with_print_hand_rendering_without_ui:
        try {
            intentApi.print("PrintingSample", "application/pdf",
                    Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PDF)));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    case R.id.change_files_options:
        try {
            List<PrintHandOption> fileOptions = intentApi.getFilesOptions();
            changeRandomOption(fileOptions);
            intentApi.setFilesOptions(fileOptions);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.taobao.weex.ui.component.WXImage.java

@Override
public void updateProperties(Map<String, Object> props) {
    super.updateProperties(props);
    WXImageView imageView;/*from  w w w  .j a v a 2  s  .  co  m*/
    ImmutableDomObject imageDom;
    if ((imageDom = getDomObject()) != null && getHostView() instanceof WXImageView) {
        imageView = (WXImageView) getHostView();
        BorderDrawable borderDrawable = WXViewUtils.getBorderDrawable(getHostView());
        float[] borderRadius;
        if (borderDrawable != null) {
            RectF borderBox = new RectF(0, 0, WXDomUtils.getContentWidth(imageDom),
                    WXDomUtils.getContentHeight(imageDom));
            borderRadius = borderDrawable.getBorderRadius(borderBox);
        } else {
            borderRadius = new float[] { 0, 0, 0, 0, 0, 0, 0, 0 };
        }
        imageView.setBorderRadius(borderRadius);

        if (imageView.getDrawable() instanceof ImageDrawable) {
            ImageDrawable imageDrawable = (ImageDrawable) imageView.getDrawable();
            float[] previousRadius = imageDrawable.getCornerRadii();
            if (!Arrays.equals(previousRadius, borderRadius)) {
                imageDrawable.setCornerRadii(borderRadius);
            }
        }
        readyToRender();
    }
}

From source file:com.android.camera.HighlightView.java

private Rect computeLayout() {
    RectF r = new RectF(mCropRect.left, mCropRect.top, mCropRect.right, mCropRect.bottom);
    mMatrix.mapRect(r);/*from w w  w  .  j a  va2 s  .  c o m*/
    return new Rect(Math.round(r.left), Math.round(r.top), Math.round(r.right), Math.round(r.bottom));
}

From source file:com.raibow.yamahaspk.filtershow.imageshow.ImageShow.java

public void drawImageAndAnimate(Canvas canvas, Bitmap image) {
    if (image == null) {
        return;/*www  . j a  va2 s .com*/
    }
    MasterImage master = MasterImage.getImage();
    Matrix m = master.computeImageToScreen(image, 0, false);
    if (m == null) {
        return;
    }

    canvas.save();

    RectF d = new RectF(0, 0, image.getWidth(), image.getHeight());
    m.mapRect(d);
    d.roundOut(mImageBounds);

    boolean showAnimatedImage = master.onGoingNewLookAnimation();
    if (!showAnimatedImage && mDidStartAnimation) {
        // animation ended, but do we have the correct image to show?
        if (master.getPreset().equals(master.getCurrentPreset())) {
            // we do, let's stop showing the animated image
            mDidStartAnimation = false;
            MasterImage.getImage().resetAnimBitmap();
        } else {
            showAnimatedImage = true;
        }
    } else if (showAnimatedImage) {
        mDidStartAnimation = true;
    }

    if (showAnimatedImage) {
        canvas.save();

        // Animation uses the image before the change
        Bitmap previousImage = master.getPreviousImage();
        Matrix mp = master.computeImageToScreen(previousImage, 0, false);
        RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight());
        mp.mapRect(dp);
        Rect previousBounds = new Rect();
        dp.roundOut(previousBounds);
        float centerX = dp.centerX();
        float centerY = dp.centerY();
        boolean needsToDrawImage = true;

        if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) {
            float maskScale = MasterImage.getImage().getMaskScale();
            if (maskScale >= 0.0f) {
                float maskW = sMask.getWidth() / 2.0f;
                float maskH = sMask.getHeight() / 2.0f;
                Point point = mActivity.hintTouchPoint(this);
                float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH);
                maskScale = maskScale * maxMaskScale;
                float x = point.x - maskW * maskScale;
                float y = point.y - maskH * maskScale;

                // Prepare the shader
                mShaderMatrix.reset();
                mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale);
                mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top);
                float scaleImageX = mImageBounds.width() / (float) image.getWidth();
                float scaleImageY = mImageBounds.height() / (float) image.getHeight();
                mShaderMatrix.preScale(scaleImageX, scaleImageY);
                mMaskPaint.reset();
                mMaskPaint.setShader(createShader(image));
                mMaskPaint.getShader().setLocalMatrix(mShaderMatrix);

                drawShadow(canvas, mImageBounds); // as needed
                canvas.drawBitmap(previousImage, m, mPaint);
                canvas.clipRect(mImageBounds);
                canvas.translate(x, y);
                canvas.scale(maskScale, maskScale);
                canvas.drawBitmap(sMask, 0, 0, mMaskPaint);
                needsToDrawImage = false;
            }
        } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) {
            Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(),
                    master.getPreviousImage().getWidth());
            Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(),
                    master.getPreviousImage().getHeight());
            float finalScale = d1.width() / (float) d2.height();
            finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction());
            canvas.rotate(master.getAnimRotationValue(), centerX, centerY);
            canvas.scale(finalScale, finalScale, centerX, centerY);
        } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) {
            if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) {
                FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master
                        .getCurrentFilterRepresentation();

                ImagePreset preset = master.getPreset();
                ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset
                        .getGeometryFilters();
                GeometryMathUtils.GeometryHolder holder = null;
                holder = GeometryMathUtils.unpackGeometry(geometry);

                if (holder.rotation.value() == 90 || holder.rotation.value() == 270) {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    }
                } else {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    }
                }
            }
        }

        if (needsToDrawImage) {
            drawShadow(canvas, previousBounds); // as needed
            canvas.drawBitmap(previousImage, mp, mPaint);
        }

        canvas.restore();
    } else {
        drawShadow(canvas, mImageBounds); // as needed
        canvas.drawBitmap(image, m, mPaint);
    }

    canvas.restore();
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

public void drawImageAndAnimate(Canvas canvas, Bitmap image) {
    if (image == null) {
        return;/*  www.  j a va 2  s  .c om*/
    }
    MasterImage master = MasterImage.getImage();
    Matrix m = master.computeImageToScreen(image, 0, false);
    if (m == null) {
        return;
    }

    canvas.save();

    RectF d = new RectF(0, 0, image.getWidth(), image.getHeight());
    m.mapRect(d);
    d.roundOut(mImageBounds);

    boolean showAnimatedImage = master.onGoingNewLookAnimation();
    if (!showAnimatedImage && mDidStartAnimation) {
        // animation ended, but do we have the correct image to show?
        if (master.getPreset().equals(master.getCurrentPreset())) {
            // we do, let's stop showing the animated image
            mDidStartAnimation = false;
            MasterImage.getImage().resetAnimBitmap();
        } else {
            showAnimatedImage = true;
        }
    } else if (showAnimatedImage) {
        mDidStartAnimation = true;
    }

    if (showAnimatedImage) {
        canvas.save();

        // Animation uses the image before the change
        Bitmap previousImage = master.getPreviousImage();
        Matrix mp = master.computeImageToScreen(previousImage, 0, false);
        RectF dp = new RectF(0, 0, previousImage.getWidth(), previousImage.getHeight());
        mp.mapRect(dp);
        Rect previousBounds = new Rect();
        dp.roundOut(previousBounds);
        float centerX = dp.centerX();
        float centerY = dp.centerY();
        boolean needsToDrawImage = true;

        if (master.getCurrentLookAnimation() == MasterImage.CIRCLE_ANIMATION) {
            float maskScale = MasterImage.getImage().getMaskScale();
            if (maskScale >= 0.0f) {
                float maskW = sMask.getWidth() / 2.0f;
                float maskH = sMask.getHeight() / 2.0f;
                Point point = mActivity.hintTouchPoint(this);
                float maxMaskScale = 2 * Math.max(getWidth(), getHeight()) / Math.min(maskW, maskH);
                maskScale = maskScale * maxMaskScale;
                float x = point.x - maskW * maskScale;
                float y = point.y - maskH * maskScale;

                // Prepare the shader
                mShaderMatrix.reset();
                mShaderMatrix.setScale(1.0f / maskScale, 1.0f / maskScale);
                mShaderMatrix.preTranslate(-x + mImageBounds.left, -y + mImageBounds.top);
                float scaleImageX = mImageBounds.width() / (float) image.getWidth();
                float scaleImageY = mImageBounds.height() / (float) image.getHeight();
                mShaderMatrix.preScale(scaleImageX, scaleImageY);
                mMaskPaint.reset();
                Shader maskShader = createShader(image);
                maskShader.setLocalMatrix(mShaderMatrix);
                mMaskPaint.setShader(maskShader);

                drawShadow(canvas, mImageBounds); // as needed
                canvas.drawBitmap(previousImage, m, mPaint);
                canvas.clipRect(mImageBounds);
                canvas.translate(x, y);
                canvas.scale(maskScale, maskScale);
                canvas.drawBitmap(sMask, 0, 0, mMaskPaint);
                needsToDrawImage = false;
            }
        } else if (master.getCurrentLookAnimation() == MasterImage.ROTATE_ANIMATION) {
            Rect d1 = computeImageBounds(master.getPreviousImage().getHeight(),
                    master.getPreviousImage().getWidth());
            Rect d2 = computeImageBounds(master.getPreviousImage().getWidth(),
                    master.getPreviousImage().getHeight());
            float finalScale = d1.width() / (float) d2.height();
            finalScale = (1.0f * (1.0f - master.getAnimFraction())) + (finalScale * master.getAnimFraction());
            canvas.rotate(master.getAnimRotationValue(), centerX, centerY);
            canvas.scale(finalScale, finalScale, centerX, centerY);
        } else if (master.getCurrentLookAnimation() == MasterImage.MIRROR_ANIMATION) {
            if (master.getCurrentFilterRepresentation() instanceof FilterMirrorRepresentation) {
                FilterMirrorRepresentation rep = (FilterMirrorRepresentation) master
                        .getCurrentFilterRepresentation();

                ImagePreset preset = master.getPreset();
                ArrayList<FilterRepresentation> geometry = (ArrayList<FilterRepresentation>) preset
                        .getGeometryFilters();
                GeometryMathUtils.GeometryHolder holder = null;
                holder = GeometryMathUtils.unpackGeometry(geometry);

                if (holder.rotation.value() == 90 || holder.rotation.value() == 270) {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    }
                } else {
                    if (rep.isHorizontal() && !rep.isVertical()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isVertical() && !rep.isHorizontal()) {
                        canvas.scale(master.getAnimRotationValue(), 1, centerX, centerY);
                    } else if (rep.isHorizontal() && rep.isVertical()) {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    } else {
                        canvas.scale(1, master.getAnimRotationValue(), centerX, centerY);
                    }
                }
            }
        }

        if (needsToDrawImage) {
            drawShadow(canvas, previousBounds); // as needed
            canvas.drawBitmap(previousImage, mp, mPaint);
        }

        canvas.restore();
    } else {
        drawShadow(canvas, mImageBounds); // as needed
        canvas.drawBitmap(image, m, mPaint);
    }

    canvas.restore();
}

From source file:com.example.gatsu.theevent.HighlightView.java

private Rect computeLayout() {

    RectF r = new RectF(mCropRect.left, mCropRect.top, mCropRect.right, mCropRect.bottom);
    mMatrix.mapRect(r);/*from   w  ww  . j a  v a2 s . com*/
    return new Rect(Math.round(r.left), Math.round(r.top), Math.round(r.right), Math.round(r.bottom));
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java

private void drawGaugeNeedle(Canvas canvas, int count, int Scale) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    float divisor = 360.0f / Scale;

    canvas.rotate((float) (divisor * count), 100, 100);

    //Inside/*from w w w .j  a  v a2s.com*/
    Paint needleInsidePaint = new Paint();
    needleInsidePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    needleInsidePaint.setColor(Color.WHITE);
    needleInsidePaint.setStrokeWidth(4);
    needleInsidePaint.setAntiAlias(true);

    Paint needleEdgePaint = new Paint();
    needleEdgePaint.setStyle(Paint.Style.STROKE);
    needleEdgePaint.setColor(Color.DKGRAY);
    needleEdgePaint.setStrokeWidth(0.5f);
    needleEdgePaint.setAntiAlias(true);

    canvas.drawOval(new RectF(95, 95, 105, 105), needleInsidePaint);
    canvas.drawOval(new RectF(95, 96, 105, 105), needleEdgePaint);

    Path needleInside = new Path();
    needleInside.moveTo(98, 98);
    needleInside.lineTo(100, 20);
    needleInside.lineTo(102, 102);
    canvas.drawPath(needleInside, needleInsidePaint);

    Path needleEdge = new Path();
    needleInside.moveTo(99, 99);
    needleInside.lineTo(99, 19);
    needleInside.lineTo(103, 103);

    canvas.drawPath(needleEdge, needleEdgePaint);
    canvas.restore();
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Clips the long edge of a bitmap, if its width and height are not equal, in order to transform
 * it into a square. Additionally, the bitmap is resized to a specific size and a border will be
 * added./*ww w.j a v a2s .c om*/
 *
 * @param bitmap
 *         The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The
 *         bitmap may not be null
 * @param size
 *         The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The
 *         size must be at least 1
 * @param borderWidth
 *         The width of the border as an {@link Integer} value in pixels. The width must be at
 *         least 0
 * @param borderColor
 *         The color of the border as an {@link Integer} value
 * @return The clipped bitmap as an instance of the class {@link Bitmap}
 */
public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth,
        @ColorInt final int borderColor) {
    ensureAtLeast(borderWidth, 0, "The border width must be at least 0");
    Bitmap clippedBitmap = clipSquare(bitmap, size);
    Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    float offset = borderWidth / 2.0f;
    Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight());
    RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset);
    canvas.drawBitmap(clippedBitmap, src, dst, null);

    if (borderWidth > 0 && Color.alpha(borderColor) != 0) {
        Paint paint = new Paint();
        paint.setFilterBitmap(false);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderWidth);
        paint.setColor(borderColor);
        offset = borderWidth / 2.0f;
        RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset);
        canvas.drawRect(bounds, paint);
    }

    return result;
}

From source file:com.mikelau.croperino.HighlightView.java

public RectF getCropRectF() {

    return new RectF(mCropRect.left, mCropRect.top, mCropRect.right, mCropRect.bottom);
}