I want to add a free hand crop functionality.
Till now I can open the picture and draw a path around the part of the image that I want to crop thanks to this code:
https://stackoverflow.com/a/18459072/2361533
But before opening the cropped image in another activity, I want to darken the outside part of the crop path, to show the user how the cropped image will be. In case he does not like the result, he could reset the image.
It would be something like the image here:
Android: Free Croping of Image
How can i do this ?
Use the following two methods as a start:
setXfermode(new PorterDuffXfermode(Mode.DARKEN));
canvas.clipPath(path, Region.Op.DIFFERENCE);
The first one is applied to a Paint object and darkens a certain region.
The second "clips" the path in your canvas and takes the inverse (using Region.Op.DIFFERENCE).
Related
I have a image from which I need create multiple smaller images by drawing rectangles on the parent image, using opencv I know how to draw a rectangle and cut it from the image using Mat and Rect, but the main problem I am facing is that the image is entered through user input and the user can choose to select any portion he/she wants to crop out, so everything needs to be dynamically operated.
The attached image will clarify things a bit
I am new to opencv with android so any help is appreciated.
also if one can provide solution without using opencv is also welcome.
I need to implement the custom image cropping instead of using the system cropping (i.e. "com.android.camera.action.CROP"). I need to know the exact position of the cropping bounding box but this information is not retrievable if I choose to use the default cropping. Besides, the bitmap image is down sampled too much by default cropping.
The steps are as following:
Create the original size bitmap from source (using uri). The
original size is about 4000x3000 which is too big.
The user defines the crop area to extract the ROI which results in resizing of the original image to fit the ImageView. (size of ImageView is about 700x700)
Record the position of the bounding box in the ImageView.
Retrieve the cropped area from the original image and create another bitmap for it.
Resize the cropped bitmap to fit the imageview size to show it on the screen.
This approach works on my device (ZTE nuoio with Android 4.3) well. However, the app crashes on Samsung S4 with Android 4.4.4 and Note 4 while performing step 1 probably because of the out-of-memory error.
Therefore, I try to do another approach that creates the bitmap which is down sampled from the source image, rather than having the original size bitmap image.
I need to have the information of the exact position of cropped area from the original image. That is the reason why I didn't use default cropping. Could you please help me out with my case either providing
the solutions to derive the exact coordinates of the bounding box of the cropped image in the original image as a matrix.
how to solve the out-of-memory error in step 1 using the approach I mentioned above.
Or other approach to achieve image cropping with knowing the exact coordinates of cropped area form the original image.
Thank you so much.
For Crop an image and get Coordinates use library Edmodo Croper https://github.com/edmodo/cropper
For Out of memory issue you have to down scale image.
I want to get the part of an image which is visible to us. There is another image over the first image. So from that image, some part of first image is visible. And I want that part only.
I’ll show you sample of it and final output which I am expecting from it.
I know how to crop in oval shape. But here, the template used in above example can be different in actual, so as per the template /mask I need to crop that image.
How can I do this. Any idea?
A simple but maybe not very efficient solution:
assume the mask is above the real image
both images are in the same container and if the mask is above the image this means that the pixels of the image would correspond to pixels of the mask
draw only those pixels of the image whose corresponding pixel in the mask is not black
I'm working on an application in which I'v a custom ImageView. Using custom imageview I can drag,zoom, and paste text over over it (using its onDraw() function). Now at the end I want to put all the canvas drawing over image and want to save it in the file system. I have tried imageView.getDrawingCache() method but it does not fulfill my requirements as when I zoom out the it captures black sides of the image too. Any suggestions?
Create or load your Bitmap.
Create Canvas.
Set the Bitmap as target for this canvas. link
Draw your text using the canvas.
Now your image stored in Bitmap has drawn stuff on top of it.
I would like to know if we can edit the picture that we take from a camera and store it on our Phone. Can we make use of android.graphics package to edit the picture.
One of the sample picture has has been edited on the top width is this as you can see the image has been clipped from the top center just below the word "Discovery". Is this possible on Andriod?
Yes, you can make a Canvas out of a bitmap, and then use canvas drawing commands to mutate and save it again.
I'm not really sure what you're asking, though.