Skip to content

Canvas increase and decrease height of Image Entity by click of buttons or seekbar #43

@rohanashik

Description

@rohanashik

The problem is when I resize the height/width of one of the bitmap inside canvas The bitmap also moving aside, But it actually should not move from x y axis while I scroll the seekbar, Thats the problem.

ezgif com-optimize

    public ImageEntity(@NonNull Layer layer,
                       @NonNull Bitmap bitmap,
                       @IntRange(from = 1) int canvasWidth,
                       @IntRange(from = 1) int canvasHeight) {
        super(layer, canvasWidth, canvasHeight);

        this.bitmap = bitmap;


        layer.widthSize(bitmap.getWidth());
        layer.heightSize(bitmap.getHeight());

        updateIMGEntity(false);
    }


    public void updateIMGEntity() {
        updateIMGEntity(true);
    }

    private void updateIMGEntity(boolean moveToPreviousCenter) {

        // save previous center
        PointF oldCenter = absoluteCenter();

        Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, layer.getWidth(),
                layer.getHeight(), false);

        // recycle previous bitmap (if not reused) as soon as possible
        if (bitmap != null && bitmap != newBitmap && !bitmap.isRecycled()) {
            bitmap.recycle();
        }

        this.bitmap = newBitmap;

        float width = bitmap.getWidth();
        float height = bitmap.getHeight();

        @SuppressWarnings("UnnecessaryLocalVariable")
        float widthAspect = 1.0F * canvasWidth / height;

        // for text we always match text width with parent width
        this.holyScale = widthAspect;

        // initial position of the entity
        srcPoints[0] = 0; srcPoints[1] = 0;
        srcPoints[2] = width; srcPoints[3] = 0;
        srcPoints[4] = width; srcPoints[5] = height;
        srcPoints[6] = 0; srcPoints[7] = height;
        srcPoints[8] = 0; srcPoints[8] = 0;

        if (moveToPreviousCenter) {
            // move to previous center
            moveCenterTo(oldCenter);

        }
    }


    @Override
    public void drawContent(@NonNull Canvas canvas, @Nullable Paint drawingPaint) {

        //updateMatrix();
        canvas.drawBitmap(bitmap, matrix, drawingPaint);
        //release();
    }
`

_Originally posted by @Rohanashik in https://github.com/uptechteam/MotionViews-Android/issues/22#issuecomment-430505071_

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions