Warp Image area on touch of a point area?
Asked Answered
C

2

9

I need a basic idea for how can i warp image on touch of a particular area. Image filters apply warp on whole image but i want to warp single point, like if i want to warp eye of a person then i will touch on that point. So I need a basic idea about this work.

I have tried this one but its also applies filters on whole image. https://github.com/Jtfinlay/PhotoWarp

App: https://play.google.com/store/apps/details?id=hu.tonuzaba.android&hl=en

Crawford answered 19/7, 2017 at 6:21 Comment(3)
refer this : #9238424Cushat
refer this : how to warp imageCushat
done with that not works up to my exceptions, saving states of warp is handy in it.Crawford
M
7

A warp is not just at a "single point" but over some area that you deform in a smooth way.

To achieve this, you need a geometric transform of the coordinates that works in some neighborhood of the touched point. One way to do this is by applying a square grid on the image and moving the grid nodes around the touched points with some law of yours (for instance, apply a displacement vector to all nodes, with a decaying factor such that far away nodes don't move).

Then you need a resampling function that computes the new coordinates of every pixel and copies the color of the source pixel.

For good results, you must actually work in reverse: scan the destination image and for every pixel retrieve the source coordinates and source pixels. Apply bilinear or bicubic resampling to avoid aliasing.

For ease of implementation, the gridding idea should be adapted as well: rather than deforming the destination grid, keep it unchanged and apply the inverse deformation to the source grid.

Last thing: in the grid approach, see the displacements of the grid nodes as two scalar functions DX(i, j) and DY(i, j) that you can handle separately. From the knowledge of the displacements at the nodes, you can estimate the displacement of any pixel by interpolation (bicubic would be appropriate here).

Mainstay answered 19/7, 2017 at 8:46 Comment(0)
N
4

you can use canvas to detect that portion and stop action on that portion in ontouchlistener

code sample

Bitmap pricetagBmp = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.ic_tag_circle_24dp);
           // canvas.drawBitmap(pricetagBmp,left + (right - left) / 2, top + (bottom - top) / 2 - (bounds.height() / 2),circlePaint);
            float imageStartX = (left + ((right-left)/2)) - (pricetagBmp.getWidth()/2);
            float  imageStartY = (top + ((bottom - top) / 2)) - (pricetagBmp.getHeight()/2);
            canvas.drawBitmap(pricetagBmp, imageStartX,  imageStartY,circlePaint);

and in ontouchlistener if that points detected you can perform no action

Note: you can replace drawBitmap with drawRect or something else with invisible color

Nonresident answered 26/7, 2017 at 5:46 Comment(2)
that is putting drawable on canvas but i want to perform some distort effect on area of touch that will modify base image instead of putting drawable but thanks for your answerCrawford
@joy Hard - I've added the note. you can change it as per your requirementNonresident

© 2022 - 2024 — McMap. All rights reserved.