Draw a line on an image javaFx - java

I have a map image in my java project when the user clicks on two cities I want to draw a line on the map image between these two cities, so if I do any effects like zooming the lines get affected too not just the image. how can I do that, any help would be appreciated.

so if I do any effects like zooming the lines get affected too not just the image.
Put the map image and the line in the same Parent (e.g. Group, Pane, etc). Then apply the zoom to the Parent Node, and not the map image directly.

Related

Slide to specific part of image in Android

I'm trying to build some kind of smart map. To do that I need to display specific part of picture (in this case floor plan). So we will have quite big picture (let's assume 3000x3000px) with some rooms (with irregular sizes and shapes) and if location changed we need to should smooth slide to this specific position. As I said before rooms will be with irregular sizes so also there should be an option to zoom out and zoom (programaticlly) in at specific position.
Use case how it should work.
App location changed
ImageView instead of displaying whole picture of floor plan smooth slide to specific coords and zoom this part of picture
Is this possible to do that on ImageView or something like PhotoView ?

Straightforward way to place text on a specific location in an image?

Overhead schematic of Docks map in Modern Warfare
Overhead schematic of Docks with one callout name
I'm creating an app that will display names - "callouts" - for various specific areas of each map in the video game Modern Warfare. I want to be able to place the text (or a placeholder) in the same location, regardless of scale, transformations, etc. Is there a way to do this besides getting the (x,y) coordinates of each location in an image editor, then using those coordinates in my layout? That method seems extremely tedious because there's 10 - 20 callouts per map, and approximately 20 maps! I also want to avoid adding the text graphically so that I can change it as necessary in Android Studio.
If I place TextViews visually in the [Design] tab in Android Studio, will they stay in the same position relative to the background ImageView, regardless of scaling, transforms, etc.? Please advise, and I'll be happy to clarify if necessary. Thanks!
I think I've found the solution I'm looking for, folks:
Within a ConstraintLayout, have an ImageView to hold the map graphic, and TextViews for each callout label.
Constrain each TextView to the Start, End, Top, and Bottom of the ImageView.
Drag the TextViews to the desired location in the [Design] tab of the layout editor. This will automatically adjust the Horizontal and Vertical Bias, which is essentially a percentage of the parent's width and height, relative to the left and top of the parent.
In my preliminary testing, this seems to preserve the location of each callout label relative to the map, which is what I was hoping for. If anyone has anything to add, please do so!

how can I create a custom clickable shape on an image in android?

I want to create a clickable image, my image has some different clickable parts in it, like this one:
I want to draw a custom shape like :
A,B,C,D,E,F
and make sure when user click on of this something happen.
the problem is I don't have any kind of idea to, how create shapes like the shapes in the image make sure it just fix on the image and in different screen size don't see a massed up thing.
Will there be more than many of such images?
If no I suggest you to create mask image for each region where black part of image represents the region and white part excludes rest.
To draw image:
create custom View
in constructor don't forget to use setWillNotDraw to true so you can do custom drawing
override View.onDraw method where you can draw main image and all others with some filters via setColorFilter.
To handle click events:
override onTouchEvent method
get touch position
compare touch position with point color in mask image
To optimise:
create mask image downscaled by some scale factor
during comparison divide touch position by scale factor
This is not ideal, but solution with vectors is non trivial I think
Take it as image and setOnclickListner for that image

Image with irregular borders to display as one concat image in java

See the above map, actually I will have following images saved:
D-Yellow.png
D-Red.png
D-Blue.png
D-Green.png
A-Yellow.png
A-Red.png
A-Blue.png
A-Green.png
and so on.
That is B-Blue.png has the area marked Bin the above map, filled with blue color
In my Java program, I will use all the images in a array.
First initially screen will have the map above, the user can change the color by inputting the respective town name(i.e. A, B, C or D) and required color. Then I should replace that particular image with the prompted image.
Example
The user tells to change A to blue color, then following should appear:
Please help me also how to display these images which have irregular borders as one image
Prepare images with transparency, and then use compositing as explained here http://docs.oracle.com/javase/tutorial/2d/advanced/compositing.html
Basically compositing is achieved by setting a composite attribute to the Graphics2D object.
Sample code available here: Blending images in java

Java: Is it possible to take a GUI Panel and output it into a picture?

So I have this chart that's a little special. Kind of like an XY plot of points but my boss wanted to look like a bunch of boxes rather than dots connected by lines. And I basically made a chart using gridlayout and a whole bunch of cells that I'll be colouring in black or white depending on the data.
Now he sorta wants it to be outputted to a image file. Is there any way to save a Panel into a picture? He wants to display not only the data but also save a visual representation of the data into an image file.
Is there any way to save a Panel into
a picture?
Screen Image
You can create a Graphics context which paints to an image. This technique is often used with animations to prepare drawings offline and swap them in place to avoid artifacts.
Typically you can use the same paint methos as used to paint your canvas.
Here are more details

Categories

Resources