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
Related
I'm trying to build an progress bar in libGDX, for that I have one full horizontal image and in two lines I trying to display 2 different widths of that image:
imageFull:
imageFull.draw(batch,10,80,600,50);
imageFull.draw(batch,10,20,100,50);
the result is:
Its looks like when the width is 'small' its stretched and looks bad.
Why I can't display only part of the image without destroying the left side of the image?
Any ideas how to fix it?
That is normal behavior. If you stretch a image without keeping it's aspect ratio it will deform, it does not know the stretchable part by itself.
9-patch will help you here but you cannot simply draw the sprite as you are doing now (maybe with SpriteDrawable though?).
If I where you I would use the Scene2D Actor named ProgressBar. Feed that a 9-patch image, then it should stretch correctly. Or just use a Image if you want to control it yourself, and feed this image a ninepatch.
A quick way to create a ninepatch is to specify it's stretching regions yourself by hardcoding it.
texture = new NinePatch(yourTexture, A, B, C, D)
Where ABCD corresponds to the following image:
Now create a Scene2D Image with that ninepatch and it should stretch properly.
If you have a this texture already in a Atlas you can also supply the line split:a,b,c,d to the image data in the .atlas file and Scene2D will automatically pick it up as a ninepatch.
If you don't want to use Scene2D and/or ninepatch (but I recommend you to use it) you have to code the behavior yourself. Or cut the texture up yourself and stick the caps on the left and right side of your rectangle. But Scene2D is invented for this and a ton more GUI functionality.
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
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
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
I need to crop an Image in irregular shape my app, i.e., I select a portion by finger and if I click crop button, the selected portion alone in the Image will be saved in SDCard.
How to achieve it?
You have to define a Path for the Shape you want to be cut out.
Then create a rectangle around it an set everything between your shape an the rectangle to transparent (Alpha Channel)
This source here should give you some hints:
https://github.com/lvillani/android-cropimage/blob/develop/src/com/android/camera/CropImage.java
Take a look at the onSaveClicked method, line 209
Refer this project:
https://github.com/coderush/FlexiCrop
It has the code to crop irregular shapes.