android: make portion of an imageview selectable - java

How do I make part of an image view selectable with a resizable rectangle? (like the crop functionality) .
the image view:
EDIT:
I have successfully drawn a rectangle on the image view,by using canvas. how do I make the drawn rectangle dragable by the user?

I suggest you to extend the ImageView. You can have a Rect variable in your class which you can use to determine the cropping area. Than you can override onTouchmethod to handle touch events to manipulate the cropping rectangle and override the onDrawto draw the cropping area over bitmap.
There is also this cropper library you can use to avoid all the hard work by the way. https://github.com/edmodo/cropper

Related

How to create a custom Android view? Using XML objects or a drawing API?

I'm trying to create a new view that would:
load an image
allow the user to zoom and rotate the image with two fingers while a "cropping box" stays translucent over the top while the image extends beyond the "cropping box"
with the end goal of being able to mark the rotation and position of the main image (so that later i could crop out or show the area within the cropping box)
I'm wondering if I can do this with an ImageView holding the image in the background and another ImageView holding the crop box on top of it, then using TouchEvents to move the image, would this work?
Or do I need to use some drawing API on a 2D surface?
I'm just really new to creating custom objects in Android that aren't just customized out-of-the-box Views.
What's the standard way of creating something like this?
Thanks!
Create a Compound View by extending RelativeLayout with two overlapping ImageViews in it. Then override onTouch event or override onGestureDetector interface in that newly created View.
Official Documentation: http://developer.android.com/guide/topics/ui/custom-components.html
Another Tutorial: http://www.vogella.com/tutorials/AndroidCustomViews/article.html

Options to put corners in Android ImageView

I'm trying to put corners im my ImageView and I find these "workarounds":
1 - Take the Bitmap soure and paint then
2 - put a second ImageView on my layout and use shape+corners as its source
It's not possible take the image view and put a corner around then?
In my app i have a List with a lot of ImageView (the Bitmap used in this ImageView's is programmatically) and I want to put corners in every ImageView.
There is any other option?
You can create a selector that contains shape with rounded corners, and then apply it as the ImageView's background using xml.
Look at this answers here
You can also do it via code by using PorterDuffXfermode. PorterDuffXfermode uses alpha compositing that will allow you to create and intersection (things of mathematical sets here) between the Canvas you get from onDraw() and an off screen Canvas you will have to create. You will use one of the PorterDuff.Mode flags to tell the framework you want to only render the pixels that intersect from the two Bitmaps in each Canvas.
More on Alpha Compositing

Animating a mask for png image in Android

So I am trying to develop an animation that fills a png into white like this:
For the transparent woman, I have a custom view that draws the png, and an AsyncTask for the animation that calls the view's invalidate() method.
I was able to draw and animate almost everything, but I cannot find a solution for filling the png from bottom to top. How can I create a "mask" that draws exactly the shape of the woman in white from bottom to top?

Crop custom shape from photo

I need to have an Android app with ImageView on the screen and user should be able to draw a custom (closed) shape (something like a circle/ellipse) made of curves to select an object on the image. The shape then has to be saved to String (like M123,21L23,30C100,29...). Does anybody know how to achieve this ? Or just point me the right direction. Thanks
If you just want to draw another bitmap on your ImageView and it shouldn't be dynamic, than use AbsoluteLayout and position them above each other.
If it should be much more dynamic, I recommend to use a SurfaceView. A tutorial can be found here: Custome Shape from Photo

Automatically crop image boundaries

I'm looking for an automatic way to grab a piece of a bitmap and extract a certain part of it.
Let me explain:
If I have this image:
http://imgur.com/B9U9E
It has a big white border. (see link for better white result) I'm looking for a way to only grab the dialog above. So no white borders around the dialog. Is there a way to do this by code or with a library?
You should know that the image could have any form and positioned anywhere on the white dialog.
So a user draws something on the white panel and i need the program to automatically make a rectangle about where the users drew on the canvas and save that bitmap where the user drew on the canvas (Everything in between that rectangle).
Pseudocode
Define the background color.
Scan from the left, right, bottom, top and store the locations of the transitions from background to drawing.
The rectangle defined by (left, bottom) and (right, top) defines the cropping area
For a Java code example, please see: How to auto crop an image white border in Java?
Look into Bitmap.createBitmap.

Categories