Well i have a circle image that i am using imageview to show in the app
I need someway to make parts of this image interactive like event should fire depend on which part of the image the user is clicking , i.e. if user is clicking on the center of the image or on one of the pie slices of the circle image
how this could be achived ?!
One way would be slicing the image into the parts, then assigning a clickevent to each part with the appropriate reaction.
the other way could be to check on the clickevent where you have clicked (x,y) and check if it is in a range you defined as an area if it's in there.
or you have different colors of the slices, you then get the color of the clicked pixel and evaluate where it belongs to
Related
How can I put an image (img2.jpg) on top of another image (img1.jpg) in an ImageView using JavaFX so that if I move ahead through the pictures of the image slider and come back to the img1.jpg, then img2.jpg stays attached on top of img1.jpg.
It's like thinking of an image of a garden (img1.jpg) and a small cat (img2.jpg) in a particular spot in the garden, it stays attached to it.
Do I use a StackPane?
I need to set an image inside the square box under the hanger, what is the best technique to set the new image over this background to exactly fit inside the box in case of small or large screen devices.
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.
I have a custom component displaying *.png image. The image has transparent and non-transparent area. If I add ActionListener(or MouseClickListener) to component, it will raise events even if I click on transparent area of component. Visually it looks like clicking outside the component.
How can I declare which area should react on clicks and which should not?
I've read about getting pixel from image your coordinates from event object and check its transparency. It seems difficult and ineffective.
Maybe define custom-border of this component or something else?
You answered your own question.
Within the mousePressed() event handler, you're going to have to check if you're within the JComponent, and then check the pixel at the x and y coordinate of the mouse click for transparency.
How can I declare which area should react on clicks and which should not?
This is done at the JComponent level by overriding the contains(...) method. So for example you extend JLabel to create a TransparentLabel which contain your image in the form of an icon.
Then whenever this method is invoked you only need to check this one location to determine if the pixel is transparent or not.
If your main issue about "overhead" is that you only want to make it opaque when the mouse enters a non-transparent part of the image, I'd consider pre-computing an image "mask".
On image load, make another image (or a 2d array, or something similar) that will be binary (i.e. black-and-white only, or 1 and 0 values only in an array). 0/white = transparent, 1/black = non-transparent.
Then, on mouse events, you can just check the exact pixel in the mask if it is set (value = black or 1), and trigger if it is.
Did you try to bunk two same pictures file and just for the second picture give it a short width ? Like that I think you will can to add differents listerners for the both pictures.
I'm wondering..
1)is it possible to set an imageview's resource to the URL location of an image?
2)is there a way of setting the x,y co-ords of where on the screen to draw the imageview?
3)How would I run a check to see if the space is taken up by another Imageview (must specifically be an imageview)
4) How would I make the Imageview "clickable" e.g if the user clicks the image it'll do something?
5) How would I dynamically create imageviews? E.g if a condition is true make another imageview
Perhaps I'm going about this wrong so I'll explain better what I'm looking to do.. basically I want to draw images on the screen which are located at URL's. I want to display N amount of images (There will be conditions which will decide how many images I'm displaying, so it'll have to be dynamically created) each image should take up approx 50x50 screen space. There will be other conditions to where the image should be displayed.. If an image exists at a certain co-ord it shouldn't draw over it, when the user clicks the image something else should happen.
Hopefully this makes things clearer.
Thanks.
Not directly. You can download image afer program was started, then convert it to Drawable and display on screen. But you cannot assume user always enables data transfer, so often image won't be downloaded at all.
Yes, but much better is to use Layouts - different handsets have different screen resolutions and desinty.
No simple answer - it depends, how you prepare and display screen contents.
((ImageView)view.findViewById(R.id.imageid)).setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//something
}
});
It sounds like you don't need ImageView (the graphics component used to place image in various layouts) itself, but rather some kind of canvas. Anyway, see:
How to add 3 images in a canvas in android
Drawing to the canvas